首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >geom_boxplot和geom_jitter

geom_boxplot和geom_jitter
EN

Stack Overflow用户
提问于 2014-02-21 21:05:41
回答 1查看 8.3K关注 0票数 1

将数据点与方框图对齐。

数据:

代码语言:javascript
复制
data<-structure(list(score = c(0.058, 0.21, -0.111, -0.103, 0.051, 
0.624, -0.023, 0.01, 0.033, -0.815, -0.505, -0.863, -0.736, -0.971, 
-0.137, -0.654, -0.689, -0.126), clin = structure(c(1L, 1L, 1L, 
1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L), .Label = 
c("Non-Sensitive", 
"Sensitive "), class = "factor"), culture = structure(c(1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("Co-culture", "Mono-culture"), class = "factor"), 
    status = structure(c(2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 
    2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L), .Label = c("new", "old"
    ), class = "factor")), .Names = c("score", "clin", "culture", 
"status"), class = "data.frame", row.names = c(NA, -18L))

代码:

代码语言:javascript
复制
p<-ggplot(data, aes(culture, as.numeric(score),fill=status))

p+geom_boxplot(outlier.shape = NA)+
   theme_bw()+scale_fill_grey(start = 0.8, end = 1)+
   labs(title="title", x="", y="score",fill="", colour="")+
   geom_jitter(aes(colour = clin), alpha=0.9, 
   position=position_jitter(w=0.1,h=0.1))

如您所见,使用geom_jitter绘制的数据点与方框图不对齐。我知道我也需要向geom_jitter提供aes元素,但我不知道如何正确地做到这一点。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-21 21:40:31

我不认为你能做到这一点,因为方格图的位置是由道奇算法驱动的,而不是一种明确的美学,不过我很好奇是否有人想出了一种方法。以下是一个解决办法:

代码语言:javascript
复制
p<-ggplot(data, aes(status, as.numeric(score),fill=status))
p+geom_boxplot(outlier.shape = NA)+
  theme_bw()+scale_fill_grey(start = 0.8, end = 1)+
  labs(title="title", x="", y="score",fill="", colour="")+
  geom_jitter(aes(colour = clin), alpha=0.9, 
              position=position_jitter(w=0.1,h=0.1)) +
  facet_wrap(~ culture)

通过使用culture的面,我们可以为status指定一个显式的美学,然后允许将geom_jittergeom_boxplot排列起来。希望这对你的目的来说已经足够接近了。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21945156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档