davidsjoberg / ggsankey

Make sankey, alluvial and sankey bump plots in ggplot
Other
262 stars 30 forks source link

Labels too wide for alluvial plot #47

Open hrdawson opened 4 months ago

hrdawson commented 4 months ago

I'd like to use the alluvial plot for some data with long variables. However, geom_alluvial_text seems to have a set width that doesn't change even when the label needs to be much wider. It would also be helpful if the vertical dimension could resize so that labels have a margin to prevent overlap, and if the labels could justify to the right/left so they don't bleed onto the ribbons. Using starwars as an example:

library(tidyverse)

df <- starwars |>
  make_long(species, homeworld)

ggplot(df, aes(x = x, next_x = next_x, node = node, next_node = next_node, fill = factor(node), label = node)) +
  geom_alluvial(flow.alpha = .6) +
  geom_alluvial_text(size = 3, color = "white") +
  scale_fill_viridis_d(drop = FALSE) +
  theme_alluvial(base_size = 18) +
  labs(x = NULL) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = .5))
Screenshot 2024-05-06 at 17 33 49

Thanks for the great package!