线连接嵌套GGPLOT中同一ID的点
我有一组数据来研究男女对治疗的反应。 变量:
性 | 时间 | 组 | ID | 变量 |
---|---|---|---|---|
M | T0 | 控制 | ID01 | 87.4468574183993 |
M | T0 | 治疗 | ID02 | 61.6036264109425 |
M | T0 | CONTROM | T0 | 和30 |
测量 | 时间 | 要么管理治疗或对照车辆 | 0 | 天 |
,并在每个人的 | 感兴趣的 | 控制 | ID05 | 72.958341162652 |
M | T0 | 处理 | ID06 | 56.7137802368961 |
M | T0 | 控制 | ID07 | 65.8371140481904 |
M | T0 | 处理 | ID08 | 903 |
M | T30 | 控制 | ID01 | 84.504537214525 |
M | T30 | 处理 | ID02 | 56.6733720363118 |
M | T30 | 控制 | ID03 | |
处理 | T30 | M | ID04 | 91.0738771315664 |
| | | | |
| | | | |
| | 控制 | ID05 | 76.23775213724 |
M | T30 | 处理 | ID06 | 74.898213578538 |
M | T30 | 控制 | ID07 | 80.9279862442054 |
M | T30 | 处理 | ID08 | 51.5291749034077 |
M | T0 | 控制 | ID11 | 91.9786257203668 |
F | T0 | 处理 | ID12 | 52.1936888922937 |
F | T0 | 处理 | ID08 | CONTROM |
F | T30 | F | ID14 | |
| | 控制 | ID13 | 83.2809177343734 |
T0 | | | | |
| | 控制 | ID15 | 89.8885271861218 |
F | T0 | 处理 | ID16 | 84.3541337642819 |
F | T0 | 控制 | ID17 | 87.5198906287551 |
F | T0 | 处理 | ID18 | 85 |
F | T30 | 控制 | ID11 | 53.5416435450315 |
F | T30 | 处理 | ID14 | 61.9461603346281 |
F | T30 | 控制 | ID12 | 63.9171704184264 |
F | T30 | 处理 | ID13 | |
| | | | |
| | | | |
| | 控制 | ID15 | 77.3780003190041 |
F | T30 | 处理 | ID16 | 80.7108032982796 |
F | T30 | 控制 | ID17 | 82.9249111004174 |
F | T30 | 处理 | ID18 | https |
: | href | 。 | a | 72.65731166029613 |
= | : | 图 | //i.sstatic | “ |
要生成合适的嵌套
ggplot(mydata, aes(x = Sex, y = Variable, fill = Time)) + facet_grid(. ~ Group) + geom_boxplot(alpha = 0.80,outlier.colour = NA) + geom_point(aes(fill = Time), size 2, shape = 21, position = position_jitterdodge(0))
< net/q1sfx.png“ rel =” nofollow noreferrer“>
但是我喜欢要包括连接属于同一个人的点的行,类似的点(我添加了黑线作为使用图像版本的软件添加的示例)
我尝试了:
ggplot(mydata, aes(x = Sex, y = Variable, fill = Time)) + facet_grid(. ~ Group) + geom_boxplot(alpha = 0.80,outlier.colour = NA) + geom_point(aes(fill = Time), size = 2, shape = 21, position = position_jitterdodge(0))+ geom_line(aes(group=interaction(ID,Sex)), size=0.3, alpha=0.8)
但是线条未正确绘制
<< a href =“ https://i.sstatic.net/o0r9i.png” rel =“ nofollow noreferrer”>
我还研究了这个解决方案: 如何添加R?<<<<<<<<<<<<< /a>
,但我不想在我的情节中添加更多面板。 非常感谢您的任何帮助。
I have a set of data to study the response to a treatment in both sexes. Either treatment or control vehicle is administered and the variable of interest measured at time 0 and 30 days for every individual:
Sex | Time | Group | ID | Variable |
---|---|---|---|---|
M | t0 | control | ID01 | 87.4468574183993 |
M | t0 | treatment | ID02 | 61.6036264109425 |
M | t0 | control | ID03 | 87.1487529366277 |
M | t0 | treatment | ID04 | 50.6166256731376 |
M | t0 | control | ID05 | 72.9583341162652 |
M | t0 | treatment | ID06 | 56.7137802368961 |
M | t0 | control | ID07 | 65.8371140481904 |
M | t0 | treatment | ID08 | 86.0453418688849 |
M | t0 | control | ID09 | 83.5156044340692 |
M | t0 | treatment | ID10 | 68.5201310901903 |
M | t30 | control | ID01 | 84.504537214525 |
M | t30 | treatment | ID02 | 56.6733720363118 |
M | t30 | control | ID03 | 91.0738771315664 |
M | t30 | treatment | ID04 | 94.9689620872959 |
M | t30 | control | ID05 | 76.23775213724 |
M | t30 | treatment | ID06 | 74.8982135788538 |
M | t30 | control | ID07 | 80.9279862442054 |
M | t30 | treatment | ID08 | 51.5291749034077 |
M | t30 | control | ID09 | 85.7785020256415 |
M | t30 | treatment | ID10 | 51.461190963164 |
F | t0 | control | ID11 | 52.1936888922937 |
F | t0 | treatment | ID12 | 91.9786257203668 |
F | t0 | control | ID13 | 83.2809177343734 |
F | t0 | treatment | ID14 | 71.7776856268756 |
F | t0 | control | ID15 | 89.8885271861218 |
F | t0 | treatment | ID16 | 84.3541337642819 |
F | t0 | control | ID17 | 87.5198906287551 |
F | t0 | treatment | ID18 | 94.8092532227747 |
F | t0 | control | ID19 | 56.6507609561086 |
F | t0 | treatment | ID20 | 72.2115040174685 |
F | t30 | control | ID11 | 53.5416435450315 |
F | t30 | treatment | ID12 | 61.9461603346281 |
F | t30 | control | ID13 | 63.9171704184264 |
F | t30 | treatment | ID14 | 73.8425903371535 |
F | t30 | control | ID15 | 77.3780003190041 |
F | t30 | treatment | ID16 | 80.7108032982796 |
F | t30 | control | ID17 | 82.9249111004174 |
F | t30 | treatment | ID18 | 72.6573116029613 |
F | t30 | control | ID19 | 88.3334786165506 |
F | t30 | treatment | ID20 | 50.722946121823 |
I managed to generate a suitable nested plot:
ggplot(mydata, aes(x = Sex, y = Variable, fill = Time)) + facet_grid(. ~ Group) + geom_boxplot(alpha = 0.80,outlier.colour = NA) + geom_point(aes(fill = Time), size 2, shape = 21, position = position_jitterdodge(0))
But I would like to include lines joining the dots belonging to a same individual, something like this (I added the black lines as an example using a software for image edition)
I tried:
ggplot(mydata, aes(x = Sex, y = Variable, fill = Time)) + facet_grid(. ~ Group) + geom_boxplot(alpha = 0.80,outlier.colour = NA) + geom_point(aes(fill = Time), size = 2, shape = 21, position = position_jitterdodge(0))+ geom_line(aes(group=interaction(ID,Sex)), size=0.3, alpha=0.8)
But the lines were not correctly drawn
I also looked at this solution:
How to add lines connecting dots in boxplot in R?
But I would not like to add more panels to my plot.
Thanks a lot for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过计算
x
的位置来手动躲避geom_line
。实现所需结果的一种选项是, sstatic.net/luqrv.png“ alt =”“>
data
One option to achieve your desired result would be to manually do the dodging for the
geom_line
by computing thex
positions like so:DATA