使用 ggalluvial 创建冲积图时出现问题
我有这个数据集:
type <- c(1, 2, NA, 1, 2, NA)
freq <- c(75, 12, 25, 69, 22, 32)
time <- c("before", "before", "before", "after", "after", "after")
df <- data.frame(type , freq, time )
我需要制作一个像这样的图表(显然有不同的数据):
我尝试按照此处的指南进行操作: https://cran.r-project.org/web/ packages/ggalluvial/vignettes/ggalluvial.html
使用此代码:
ggplot(modechoice,
aes(x = time, stratum = type, alluvium = time,
y = freq,
fill = type, label = type)) +
scale_x_discrete(expand = c(.1, .1)) +
geom_flow() +
geom_stratum(alpha = .5) +
geom_text(stat = "stratum", size = 3) +
theme(legend.position = "none") +
ggtitle("x")
但我收到错误,我的数据未被识别为冲积层。我做错了什么?
I have this dataset:
type <- c(1, 2, NA, 1, 2, NA)
freq <- c(75, 12, 25, 69, 22, 32)
time <- c("before", "before", "before", "after", "after", "after")
df <- data.frame(type , freq, time )
I need to make a graph like this (with different data obviously):
I tried to follow the guide here:
https://cran.r-project.org/web/packages/ggalluvial/vignettes/ggalluvial.html
Using this code:
ggplot(modechoice,
aes(x = time, stratum = type, alluvium = time,
y = freq,
fill = type, label = type)) +
scale_x_discrete(expand = c(.1, .1)) +
geom_flow() +
geom_stratum(alpha = .5) +
geom_text(stat = "stratum", size = 3) +
theme(legend.position = "none") +
ggtitle("x")
But I get the error that my data is not recognised as an alluvial. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该有第四个变量,它与您的
time
变量链接,这就是我创建一个额外变量作为示例的原因。您可以使用以下代码:输出:
在 Victor Nielson 评论后编辑:
输出:
You should have a fourth variable which is linked with your
time
variable, that's why I created an extra variable as an example. You can use the following code:Output:
Edit after Victor Nielson comment:
Output: