[英]Overlap measurement points on a grouped geom_boxplot() using ggplot2
我的数据看起来像这样
d1 <- data.frame(BAI2013 = rnorm(30),
class = rep(letters[1:3], 10),
treatment = rep(c("elevated","ambient"),15))
我绘制了以下箱线图,包括测量点并消除异常值:
p<- (ggplot(d1, aes(x = class, y = BAI2013)))
p + geom_boxplot(outlier.size = 0, aes(fill=factor(treatment))) +
geom_point(aes(color = factor(treatment)))
如您所见,问题在于,在x轴上绘制的点对应于class
,而我希望这些点与每个框重叠,而不是与每个组的中心重叠。 谢谢
如果您希望他们居中,可以使用position_dodge()
:
p + geom_boxplot(outlier.size = 0, aes(fill=factor(treatment))) +
geom_point(aes(color = factor(treatment)), position = position_dodge(width = 0.75))
如果您希望它们抖动, 那会比较棘手 ,但有可能
您可以尝试从
p<- (ggplot(d1, aes(x = interaction(class, treatment), y = BAI2013)))
然后,您必须考虑所需的标签/顺序实际是什么样子,但是所有内容都将排成一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.