在以下示例中,均值和se是从原始数据中计算出来的,并以barplot绘制。我想做同样的事情,但我不想使用barplot,而是要使用连接点。所以,如果有人可以告诉我如何...我将非常感激...谢谢
例:
data(ToothGrowth)
ToothGrowth$F3 <- letters[1:2]
# coerce dose to a factor
ToothGrowth$dose <- factor(ToothGrowth$dose, levels = c(0.5,1,2))
# facetting on the third factor
ggplot(ToothGrowth, aes(y = len, x = supp )) +
stat_summary(fun.y = 'mean', fun.ymin = function(x) 0, geom = 'bar',
aes(fill =dose), position = 'dodge') +
stat_summary(fun.ymin = function(x) mean(x) - sd(x),
fun.ymax = function(x) mean(x) + sd(x), position ='dodge',
geom = 'errorbar', aes(group = dose))+
facet_wrap(~F3)
最佳答案
您可以将geom pointrange
用于指示均值和误差线的两个点。
ggplot(ToothGrowth, aes(y = len, x = supp, colour = dose, group = dose)) +
stat_summary(fun.y = mean,
fun.ymin = function(x) mean(x) - sd(x),
fun.ymax = function(x) mean(x) + sd(x),
geom = "pointrange") +
stat_summary(fun.y = mean,
geom = "line") +
facet_wrap( ~ F3)
关于r - 在ggplot2中使用stat_summary计算平均值和sd,然后连接误差线的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21239418/