【发布时间】:2020-09-30 23:11:24
【问题描述】:
我想使用 ggplot2 和 ggalluvial 修改现有的 sankey 图,使其更具吸引力
我的例子来自https://corybrunson.github.io/ggalluvial/articles/ggalluvial.html
library(ggplot2)
library(ggalluvial)
data(vaccinations)
levels(vaccinations$response) <- rev(levels(vaccinations$response))
ggplot(vaccinations,
aes(x = survey, stratum = response, alluvium = subject,
y = freq,
fill = response, label = response)) +
scale_x_discrete(expand = c(.1, .1)) +
geom_flow() +
geom_stratum(alpha = .5) +
geom_text(stat = "stratum", size = 3) +
theme(legend.position = "none") +
ggtitle("vaccination survey responses at three points in time")
由reprex package (v0.3.0) 于 2020 年 10 月 1 日创建
现在,我想更改此图,使其看起来类似于 https://sciolisticramblings.wordpress.com/2018/11/23/sankey-charts-the-new-pie-chart/ 中的图,即 1. 将绝对值更改为相对值(百分比) 2. 添加百分比标签和 3. 应用部分填充(例如“缺失“ 绝不”)
我的方法:
我想我可以将轴更改为百分比,例如:scale_y_continuous(label = scales::percent_format(scale = 100))
但是,我不确定第 2 步和第 3 步。
【问题讨论】:
标签: r ggplot2 dataflow sankey-diagram