[英]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.