*disclaimer
1198101
標準誤差
平均±標準誤差
標準誤差の計算
se = sd/sqrt(項目数)
先に平均とSEを計算しておく
geom_errorbar
geom_errorbar(aes(ymin=平均-SE, ymax=平均+SE), width=.2)
- 横幅は width=.2くらいが適当
```{r}
library(dplyr)
sugi_iwa_mean_sd_se <- sugi_iwa.dat %>%
group_by(cond, time) %>%
summarise(mean=mean(score), sd=sd(score), se=sd/sqrt(20))
```
```{r}
g <- ggplot(sugi_iwa_se)
g <- g + aes(x=time, y=mean, color=cond)
g <- g + geom_line()
g <- g + geom_errorbar(aes(ymin=mean-se, ymax=mean+se))
plot(g)
```
```{r}
g <- ggplot(sugi_iwa_se)
g <- g + aes(x=time, y=mean, color=cond)
g <- g + geom_line()
g <- g + geom_errorbar(aes(ymin=mean-se, ymax=mean+se))
plot(g)
```
ggplotの式の中で計算する
g <- ggplot(sugi_iwa.dat)
g <- g + aes(x=time, y= score, color=cond)
g <- g + geom_point()
g <- g + geom_jitter(width = 0.05)
g <- g + facet_grid(rows = vars(cond))
g <- g + stat_summary(fun = mean,
fun.min = function(x) mean(x) - sd(x),
fun.max = function(x) mean(x) + sd(x),
geom = "pointrange", color="black", size=0.7)
g <- g + stat_summary(fun = mean,
geom = "line", width=2)
plot(g)
plotrixパッケージ
References
- https://qiita.com/Surku/items/ae16d444d6c22b0dc4e6
- 使いまわすには、自作関数seを作っておけば便利という指摘。なるほど。
se <- function(x){
sd(x)/sqrt(length(x))
}
https://sugiura-ken.org/wiki/