How to add a title above axis1 and axis2 in geom_alluvium?
Similar to
Current code:
library(ggplot2)
library(ggalluvial)
df = data.frame(
before = factor(c(4,2,3,1,1,1,2,4,2,2,1,4,3), labels = c("a","b","c","d")),
after = factor(c(3,3,2,1,3,4,4,1,1,2,2,4,3), labels = c("a","b","c","d")),
N = c(4,1,1,2,1,2,1,1,1,1,1,1,1)
)
ggplot(df, aes(y = N, axis1 = before, axis2 = after)) +
geom_alluvium(aes(fill = before)) +
geom_stratum() +
geom_text(stat = "stratum", mapping = aes(label = after_stat(stratum)))
You could add a plain old
geom_label
:Or, if you want to make it look like the labels are 'above' the plot, you could do:
Or, if that feels like cheating, you can use
annotate
: