在轴 geom_alluvium 上方添加标题
如何在geom_alluvium中的axis1和axis2上方添加标题?
类似于
当前代码:
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)))
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)))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以添加一个普通的旧
geom_label
:或者,如果您想让标签看起来像在绘图“上方”,您可以这样做:
或者,如果这感觉像是作弊,您可以使用
annotate
: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
: