本文介绍了对ggplot2中的多个X使用geom_point和geom_line的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 所以我有一个data.frame: 计划人员X mm mean_mm 1 1 95 0.323000 0.400303 1 2 275 0.341818 0.400303 1 3 2 0.618000 0.400303 1 4 75 0.320000 0.400303 1 5 13 0.399000 0.400303 1 6 20 0.400000 0.400303 2 1 219 0.393000 0.353350 2 2 50 0.060000 0.353350 2 3 213 0.390000 0.353350 2 4 204 0.496100 0.353350 2 5 19 0.393000 0.353350 2 6 201 0.388000 0.353350 etc计划== 40 我想使用ggplot2绘制点mm(由X着色),但在每个Plan中为从person 1到person 6的mm_mean绘制一条线。我已经使用代码来绘制mm(按计划排序): mc.points geom_point()+ labs(x =Plan / Person,y =mm)+ scale_colour_gradient2(high =red,mid =green,limits = c(0,1),guide =colourbar) 这是成功的。但是不确定是否添加geom_line()来绘制mm_mean线就足够了,因为我没有在上面的代码中指定mm_mean(虽然它可以绘制在y轴上,因为它的平均值)。如果是这样,这怎么办?如果我想继续在这个与mm或mm_mean无关的变量上添加变量,这个工作是否可行? 如果需要,我可以提供更多信息解决方案类似这样的事情? ggplot(df,aes(x = Person,y = mm,color = X))+ geom_point( size = 3)+ geom_hline(aes(yintercept = mean_mm))+ facet_wrap(〜Plan) So I have a data.frame:Plan Person X mm mean_mm1 1 95 0.323000 0.4003031 2 275 0.341818 0.4003031 3 2 0.618000 0.4003031 4 75 0.320000 0.4003031 5 13 0.399000 0.4003031 6 20 0.400000 0.4003032 1 219 0.393000 0.3533502 2 50 0.060000 0.3533502 3 213 0.390000 0.3533502 4 204 0.496100 0.3533502 5 19 0.393000 0.3533502 6 201 0.388000 0.353350etc to Plan == 40I want to use ggplot2 to plot points mm (colored by X) but have a plot a line for mm_mean from person 1 to person 6 in each Plan. I've used the code to plot mm (sorted by plan):mc.points <- ggplot(sam,aes(x = person,y = mm, colour = X, size = 3)) +geom_point() +labs(x = "Plan/Person",y = "mm") +scale_colour_gradient2(high="red", mid="green", limits=c(0,1), guide = "colourbar")Which is successful. But not sure if adding geom_line() to plot the mm_mean line will be enough given I haven't specified mm_mean in the above code (although it can be plotted against the y axis given its the mean of this). And if so, how can this be done? And will this work if I want to keep adding variables on top of this which are not related to mm or mm_mean?I can provide more info if needed 解决方案 Something like this? ggplot(df, aes(x = Person,y = mm, colour = X)) + geom_point(size = 3) + geom_hline(aes(yintercept = mean_mm)) + facet_wrap(~ Plan) 这篇关于对ggplot2中的多个X使用geom_point和geom_line的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 05-30 19:38