在geom_boxplot上覆盖geom_points()(fill = group)? [英] Overlay geom_points() on geom_boxplot(fill=group)?

查看:1072
本文介绍了在geom_boxplot上覆盖geom_points()(fill = group)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  require(ggplot2)
value< - rnorm(40 (rep('A',20),rep('B',20))
group <-rep(c(' (数据,aes(x =变量,y =值)),
data < - data.frame(value,variable,group)

ggplot )+
geom_boxplot(aes(fill = group))+
geom_point(aes())

按照我想要的方式,通过变量将箱形图分成组。但是,所有组的要点都是重叠的,我想将它分成组。

解决方案

使用 position_dodge()为点添加 group = group aes()中添加 geom_point()

  ggplot(data,aes(x = variable,y = value))+ 
geom_boxplot(aes(fill = group))+
geom_point(position = position_dodge(width = 0.75),aes(group = group))


Here is my code at the moment:

require(ggplot2)
value <- rnorm(40, mean = 10, sd = 1)
variable <- c(rep('A', 20), rep('B', 20))
group <- rep(c('Control', 'Disease'), 20)
data <- data.frame(value, variable, group)

ggplot(data, aes(x=variable, y=value)) +
  geom_boxplot(aes(fill=group)) +
  geom_point(aes())

This divides up boxplots into groups by variable the way I'd like. However, the points for all groups are overlaid, and I'd like for it to be divided up into groups. How would I go about doing this?

解决方案

Use position_dodge() for the points and also add group=group inside aes() of geom_point().

ggplot(data, aes(x=variable, y=value)) +
  geom_boxplot(aes(fill=group)) +
  geom_point(position=position_dodge(width=0.75),aes(group=group))

这篇关于在geom_boxplot上覆盖geom_points()(fill = group)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆