I'm looking for the most convenient way for adding rounded percentage labels to strata of an alluvial plot. There are 50 cases in the following example. Independently of stages 1 or 2, each case belongs to one group of A, B or C. I'd like to display the relative group affiliation during each stage.
library(ggplot2)
library(ggalluvial)
df <- data.frame('id' = rep(1:50,2),
'stage' = c(rep(1,50), rep(2,50)),
'group' = sample(c('A','B','C'), 100, replace = TRUE))
ggplot(df,
aes(x = stage, stratum = group, alluvium = id, fill = group)) +
scale_x_discrete(expand = c(.1, .1)) +
geom_flow() +
geom_stratum(alpha = .5)
Is there a way to add rounded percentage labels (including "%") to the strata (bar segments) without calculating a percentage column in the initial data frame? If I'm not completely mistaken, geom_text doesn't work the same way here as in geom_bar().


