在以下示例中,从原始数据计算Mean和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)
Run Code Online (Sandbox Code Playgroud)
Sve*_*ein 21
您可以将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)
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
30969 次 |
| 最近记录: |