小编Chr*_*son的帖子

如何将箱线图稍微向左或向右移动其原始位置?

我想在 ggplot 中的箱线图旁边绘制数据点。但是,我只能让 geom_boxplot 对象位于我的数据点之上。有没有办法可以将它们移过来以获得与此相似的图形?

带有与数据点相邻的箱线图的图

这是可重现的代码和一个 ggplot 对象(无格式),它将箱线图放在点上。(我知道我也可以使箱线图透明,但我更喜欢在数据旁边)

a = rep("a",100)
b = rep("b",100)
foo = as.data.frame(cbind(c(rep("a",100),rep("b",100)),c(rnorm(100,15,2.5),rnorm(100,17.5,3.2))))
colnames(foo) = c("series","value")
foo$series = as.factor(foo$series)
foo$value = as.numeric(foo$value)

ggplot(foo, aes(x = series, y = value))+
  geom_point(position = position_jitter(width = 0.1))+
  geom_boxplot(width = 0.25)
Run Code Online (Sandbox Code Playgroud)

ggplot 对象与数据点上的箱线图

谢谢!

r ggplot2 boxplot

5
推荐指数
1
解决办法
36
查看次数

标签 统计

boxplot ×1

ggplot2 ×1

r ×1