ggforce icon indicating copy to clipboard operation
ggforce copied to clipboard

Add support for nudge_x/nudge_y in geom_parallel_sets_labels

Open ycl6 opened this issue 2 years ago • 0 comments

This PR adds support for using nudge_x and nudge_y in geom_parallel_sets_labels when creating parallel sets diagrams. It is especially useful when the labels are too long to fit inside the bars depicting the discrete categories.

This enhancement allows the labels to be placed beside the categories.

library(ggforce)
#> Loading required package: ggplot2
data <- reshape2::melt(Titanic)
data <- gather_set_data(data, 1:4)

ggplot(data, aes(x, id = id, split = y, value = value)) +
  geom_parallel_sets(aes(fill = Sex), alpha = 0.3, axis.width = 0.1) +
  geom_parallel_sets_axes(axis.width = 0.1) +
  geom_parallel_sets_labels(colour = 'white')


# Use nudge_x to offset and hjust = 0 to left-justify label
ggplot(data, aes(x, id = id, split = y, value = value)) +
  geom_parallel_sets(aes(fill = Sex), alpha = 0.3, axis.width = 0.1) +
  geom_parallel_sets_axes(axis.width = 0.1) +
  geom_parallel_sets_labels(colour = 'red', angle = 0, nudge_x = 0.1, hjust = 0)

Created on 2022-04-05 by the reprex package (v2.0.1)

ycl6 avatar Apr 05 '22 13:04 ycl6