如何使用ggplot在R中创建意大利面图?
我有一个看起来像这样的数据集:
Study_ID time_point value
1 100 Time1 15
2 100 Time2 50
3 100 Time3 120
4 200 Time1 20
5 200 Time2 35
6 200 Time3 150
7 300 Time1 35
8 300 Time2 67
9 300 Time3 95
每个患者(study_id)在3个时间点(时间1,时间2和时间3)中有3行,每个患者的值为每个。
我想在x轴上创建一个带有time_point的意大利面图,以及y轴上的值,每个患者都有一条线。我所需的输出看起来像这样:
我该怎么做?
可重复的数据:
data<-data.frame(Study_ID=c("100","100","100","200","200","200","300","300","300"),time_point=c("Time1","Time2","Time3","Time1","Time2","Time3","Time1","Time2","Time3"),value=c("15","50","120","20","35","150","35","67","95"))
I have a dataset that looks like this:
Study_ID time_point value
1 100 Time1 15
2 100 Time2 50
3 100 Time3 120
4 200 Time1 20
5 200 Time2 35
6 200 Time3 150
7 300 Time1 35
8 300 Time2 67
9 300 Time3 95
Where each patient (Study_ID) has 3 rows for the 3 time-points (Time 1, Time 2, and Time 3), with a value for each.
I would like to create a spaghetti plot with time_point on the x-axis, and the value on the y-axis, with a line for each patient. My desired output would look something like this:
How can I go about doing this?
Reproducible data:
data<-data.frame(Study_ID=c("100","100","100","200","200","200","300","300","300"),time_point=c("Time1","Time2","Time3","Time1","Time2","Time3","Time1","Time2","Time3"),value=c("15","50","120","20","35","150","35","67","95"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过使用
group
和color
aes()
中的参数,您可以添加图层geom_point()
和<代码> geom_line()将颜色和组保持在一起。在2022-06-20创建的 reprex软件包(v2.0.1)
By using the
group
andcolor
arguments withinaes()
you can then add the layersgeom_point()
andgeom_line()
to keep color and group together.Created on 2022-06-20 by the reprex package (v2.0.1)