简体   繁体   English

如何创建带平均值的带状图,表示为短线而不是 R 中的点?

[英]How can I create a stripchart with mean represented as a short line instead of dot in R?

I would like to create a stripchart that looks like this:我想创建一个如下所示的条形图:

在此处输入图片说明

But I was only able to create something similar using stat_summary crossbar:但我只能使用 stat_summary crossbar 创建类似的东西:

ggplot(data, aes(x=variable, y=value)) + 
stat_summary(fun.data="mean_sdl", fun.args = list(mult=1), geom="crossbar", width=0.5) +
geom_jitter(position=position_jitter(0.2))

The result is this:结果是这样的:

在此处输入图片说明

I would be grateful for any advice on how to modify the code so I can get a graph like in the first image.对于如何修改代码的任何建议,我将不胜感激,这样我就可以获得像第一张图片那样的图表。

You can use the beeswarm package:您可以使用beeswarm包:

library (beeswarm)

beeswarm(len ~ dose, data = ToothGrowth, 
    col = 4, pch = 16,
    main = 'beeswarm + bxplot')
  bxplot(len ~ dose, data = ToothGrowth, add = TRUE)

在此处输入图片说明

ggplot(mtcars, aes(factor(cyl), qsec)) +
    geom_jitter(position = position_jitter(width = 0.2)) +
    stat_summary(fun.data = 'mean_sdl', geom = 'errorbar', width = 0.3) +
    stat_summary(fun.y = mean, geom = 'point', size = 20, shape = '_')

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM