本文介绍了结合使用geom_boxplot和geom_line的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用ggplot2
组合箱形图和线形图.但是,我在为每个组(g
)的连接线(在x轴上的各个类别上连接线)而苦苦挣扎.
I would like to combine a boxplot and a line plot using ggplot2
. However, I am struggling to have lines for each group (g
) connecting points across the categories on the x-axis.
演示问题:
df <- data.frame(x = rep(letters[1:3],each=5),
y = c(1:5,sample(10,5),1:5),
g = rep(LETTERS[1:5],3) )
library(ggplot2)
ggplot(df, aes(x=x,y=y)) + geom_boxplot() + geom_point(aes(colour = g))
我想有一条连接所有A
点的线,一条连接所有B
点的线,依此类推.
I want to have a line connecting all A
points, a line connecting all B
points and so on.
我在这里查看了一些答案,但是我无法将它们合并.他们建议使用group=1
,但这不适合我在g
中每个组的单独行.可以使用stat_summary
吗?
I have looked at some answers here but I cannot incorporate them. They suggest using group=1
but this will not suit my individual lines for each group in g
. Is it possible using stat_summary
maybe?
推荐答案
... + geom_line(aes(group = g))
这篇关于结合使用geom_boxplot和geom_line的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!