GGPLOT 2中的着色线
我有下一个数据集。
code2 clinical.pathway variable value
1 6002536 Primary Rehabilitation 1 19
2 6002536 Primary Rehabilitation 2 23
3 6002536 Primary Rehabilitation 3 22
4 6002536 Primary Rehabilitation 4 76
5 6002598 Primary Rehabilitation 1 16
6 6002598 Primary Rehabilitation 2 19
7 6002598 Primary Rehabilitation 3 51
8 6002598 Primary Rehabilitation 4 83
9 6002602 Hand Surgery 1 68
10 6002602 Hand Surgery 2 29
11 6002602 Hand Surgery 3 29
12 6002602 Hand Surgery 4 71
.....
在临床途径中,我有更多因素,在这种情况下4。
我正在处理下一个情节,将其视为重复措施。
ggplot(data)+
geom_point(aes(x=variable,y=value,color=clinical.pathway),size=1.5,show.legend = F)+
facet_wrap(~clinical.pathway)
我想以与点相同的颜色行加入每个点。 像这样:
使用的代码是下一个。但是,我不知道如何处理绘制的不同颜色。如果我将参数颜色在线上更改,
ggplot(data)+geom_point(aes(x=variable,y=value,color=clinical.pathway),size=1.5,show.legend =
F)+
geom_line(aes(x=variable,y=value,color=code2),show.legend=F)+
facet_wrap(~clinical.pathway)
如果我将其作为颜色参数临床。路径我会得到错误的图:
ggplot(data)+geom_point(aes(x=variable,y=value,color=clinical.pathway),size=1.5,show.legend
=
F)+
geom_line(aes(x=variable,y=value,color=clinical.pathway),show.legend=F)+
facet_wrap(~clinical.pathway)
一些来处理它的示例数据是下一个:
structure(list(code2 = c("1234567", "6010480", "6011819", "6011122",
"6011250", "6013164", "6014847", "6005343", "6009382", "6004114",
"6013375", "6004627", "6006660", "6011440", "6012721", "6009379",
"6002612", "6006652", "6009384", "6004392", "6010087", "6010592",
"6010056", "6010733", "6009028", "1231234", "6011250", "6006607",
"6002612", "1234567", "6013595", "6008624", "6008624", "6014886",
"6012847", "6010859", "6012437", "6013322", "6011382", "6004755",
"6010758", "6012818", "6014147", "6004334", "6014223", "6012656",
"6004669", "6009028", "6007505", "6011445", "6010106", "6011135",
"6014567", "6010055", "6005026", "6005158", "6014426", "6013595",
"6014148", "6010307"), clinical.pathway = c("Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Spine", "Primary Rehabilitation",
"Breding", "Pain Treatment", "Breding", "Breding",
"Breding", "Primary Rehabilitation", "Pain Treatment", "Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Breding",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Breding", "Breding", "Primary Rehabilitation", "Breding",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Lectures",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Breding", "Breding", "Breding",
"Primary Rehabilitation", "Breding", "Primary Rehabilitation",
"Breding", "Cooking", "Cooking",
"Cooking", "Spine", "Cooking",
"Lectures", "Cooking", "Cooking",
"Cooking", "Cooking", "Pain Treatment",
"Cooking"), variable = c(1, 4, 3, 4, 4, 1, 2,
4, 4, 3, 4, 3, 1, 3, 3, 3, 2, 3, 3, 2, 2, 3, 4, 2, 3, 4, 3, 3,
1, 2, 1, 1, 3, 4, 4, 1, 1, 3, 3, 1, 2, 3, 3, 4, 2, 1, 1, 2, 1,
1, 3, 2, 4, 1, 2, 1, 4, 3, 1, 1), value = c(9, 20, 49, 41, 31,
28, 29, 21, NA, 15, 30, 51, 77, 48, 29, 36, 22, 36, 67, 0, 16,
12, 98, 30, 45, 17, 24, 14, 19, 45, 15, 15, 16, 60, 63, 10, 67,
22, 27, 30, 43, 23, 24, 67, 20, 38, 0, 53, 39, 28, 70, 17, 56,
I have the next dataset.
code2 clinical.pathway variable value
1 6002536 Primary Rehabilitation 1 19
2 6002536 Primary Rehabilitation 2 23
3 6002536 Primary Rehabilitation 3 22
4 6002536 Primary Rehabilitation 4 76
5 6002598 Primary Rehabilitation 1 16
6 6002598 Primary Rehabilitation 2 19
7 6002598 Primary Rehabilitation 3 51
8 6002598 Primary Rehabilitation 4 83
9 6002602 Hand Surgery 1 68
10 6002602 Hand Surgery 2 29
11 6002602 Hand Surgery 3 29
12 6002602 Hand Surgery 4 71
.....
In clinical pathway I have more factors, in this case 4 more.
I am dealing with the next plot considering as repeated measures.
ggplot(data)+
geom_point(aes(x=variable,y=value,color=clinical.pathway),size=1.5,show.legend = F)+
facet_wrap(~clinical.pathway)
I would like to join every point with a line of the same colour as the point.
Something like this:
The code used was the next down. But, I dont know how to deal with the different colors plotted. If I change the parameter color in line I get a diferent result
ggplot(data)+geom_point(aes(x=variable,y=value,color=clinical.pathway),size=1.5,show.legend =
F)+
geom_line(aes(x=variable,y=value,color=code2),show.legend=F)+
facet_wrap(~clinical.pathway)
If I put as color parameter clinical.pathway I get a wrong plot like this:
ggplot(data)+geom_point(aes(x=variable,y=value,color=clinical.pathway),size=1.5,show.legend
=
F)+
geom_line(aes(x=variable,y=value,color=clinical.pathway),show.legend=F)+
facet_wrap(~clinical.pathway)
Some sample data to deal with it is the next one:
structure(list(code2 = c("1234567", "6010480", "6011819", "6011122",
"6011250", "6013164", "6014847", "6005343", "6009382", "6004114",
"6013375", "6004627", "6006660", "6011440", "6012721", "6009379",
"6002612", "6006652", "6009384", "6004392", "6010087", "6010592",
"6010056", "6010733", "6009028", "1231234", "6011250", "6006607",
"6002612", "1234567", "6013595", "6008624", "6008624", "6014886",
"6012847", "6010859", "6012437", "6013322", "6011382", "6004755",
"6010758", "6012818", "6014147", "6004334", "6014223", "6012656",
"6004669", "6009028", "6007505", "6011445", "6010106", "6011135",
"6014567", "6010055", "6005026", "6005158", "6014426", "6013595",
"6014148", "6010307"), clinical.pathway = c("Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Spine", "Primary Rehabilitation",
"Breding", "Pain Treatment", "Breding", "Breding",
"Breding", "Primary Rehabilitation", "Pain Treatment", "Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Breding",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Breding", "Breding", "Primary Rehabilitation", "Breding",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Primary Rehabilitation", "Lectures",
"Primary Rehabilitation", "Primary Rehabilitation", "Primary Rehabilitation",
"Primary Rehabilitation", "Breding", "Breding", "Breding",
"Primary Rehabilitation", "Breding", "Primary Rehabilitation",
"Breding", "Cooking", "Cooking",
"Cooking", "Spine", "Cooking",
"Lectures", "Cooking", "Cooking",
"Cooking", "Cooking", "Pain Treatment",
"Cooking"), variable = c(1, 4, 3, 4, 4, 1, 2,
4, 4, 3, 4, 3, 1, 3, 3, 3, 2, 3, 3, 2, 2, 3, 4, 2, 3, 4, 3, 3,
1, 2, 1, 1, 3, 4, 4, 1, 1, 3, 3, 1, 2, 3, 3, 4, 2, 1, 1, 2, 1,
1, 3, 2, 4, 1, 2, 1, 4, 3, 1, 1), value = c(9, 20, 49, 41, 31,
28, 29, 21, NA, 15, 30, 51, 77, 48, 29, 36, 22, 36, 67, 0, 16,
12, 98, 30, 45, 17, 24, 14, 19, 45, 15, 15, 16, 60, 63, 10, 67,
22, 27, 30, 43, 23, 24, 67, 20, 38, 0, 53, 39, 28, 70, 17, 56,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是你想要的吗?
在2022-05-12上由 reprex软件包(v2.0.1)
Is this what you want?
Created on 2022-05-12 by the reprex package (v2.0.1)