如何创建带状图,其均值表示为短线而不是 R 中的点?
How can I create a stripchart with mean represented as a short line instead of dot in R?
我想创建一个如下所示的带状图:
但我只能使用 stat_summary 横杆创建类似的东西:
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))
结果是这样的:
如有任何关于如何修改代码的建议,我将不胜感激,这样我就可以获得第一张图片中的图表。
您可以使用 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 = '_')
我想创建一个如下所示的带状图:
但我只能使用 stat_summary 横杆创建类似的东西:
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))
结果是这样的:
如有任何关于如何修改代码的建议,我将不胜感激,这样我就可以获得第一张图片中的图表。
您可以使用 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 = '_')