gpt4 book ai didi

r - 使用 ggplot 或 R 中的任何其他方法根据计数绘制线宽(大小)

转载 作者:行者123 更新时间:2023-12-01 13:36:14 25 4
gpt4 key购买 nike

我有一个长格式的数据集,每个ID“走”3步,每一步(变量名称是step)可以降落在不同的位置(变量名称是milestone),我想绘制所有路径。因为有一些路径的行进次数较多,所以我想让路径的宽度(大小)与其计数成正比。我想象它类似于 ggplot 中的 geom_line(aes(size=..count..)) ,但它不起作用。

下面是我的代码,在代码中您可以找到示例数据集的 url。我添加宽度的愚蠢解决方案是避开这条线,但它不成比例,并且会留下裂缝。

ddnew <- read.csv("https://raw.github.com/bossaround/question/master/data9.csv" ) 
ggplot(ddnew, aes(x=step, y=milestone, group=user_id)) +
geom_line(position = position_dodge(width=0.05)) +
scale_x_discrete(limits=c("0","1","2","3","4","5","6","7","8","9")) +
scale_y_discrete(limits=c("0","1","2","3","4","5","6","7","8","9"))

我当前代码的图看起来像这样,但你可以看到裂缝,而且它不成比例。 enter image description here

我希望这看起来像桑基图,宽度指示计数。

最佳答案

这有帮助吗?

library(ggplot2)
ddnew <- read.csv("https://raw.github.com/bossaround/question/master/data9.csv" )
ggplot(ddnew, aes(x=step, y=milestone, group=user_id)) +
stat_summary(geom="line", fun.y = "sum", aes(size=milestone),alpha=0.2, color="grey50")+
scale_x_discrete(limits=factor(0:2)) +
scale_y_discrete(limits=factor(0:10)) +
theme(panel.background = element_blank(),
legend.position = "none")

关于r - 使用 ggplot 或 R 中的任何其他方法根据计数绘制线宽(大小),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43404203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com