Alluvial plot冲积图
1.ggalluvial包绘制Alluvial plot,使用的数据集是R自带的vaccinations,简单绘图如下:
library(ggalluvial)
ggplot(data = vaccinations,
aes(axis1 = survey, axis2 = response, y = freq)) +
geom_alluvium(aes(fill = response)) +
geom_stratum() +
geom_text(stat = "stratum",
aes(label = after_stat(stratum))) +
scale_x_discrete(limits = c("Survey", "Response"),
expand = c(0.15, 0.05)) +
theme_void()
2.如果数据集包含更多类别变量,可以将它们传递给aes(aex1,aex2,…等等)
library(ggalluvial)
ggplot(data = vaccinations,
aes(axis1 = survey, # First variable on the X-axis
axis2 = response, # Second variable on the X-axis
axis3 = survey, # Third variable on the X-axis
y = freq)) +
geom_alluvium(aes(fill = response)) +
geom_stratum() +
geom_text(stat = "stratum",
aes(label = after_stat(stratum))) +
scale_x_discrete(limits