■
> d<-read.csv("data2.csv")
> library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
Warning message:
package ‘dplyr’ was built under R version 3.3.3
> dg<-group_by(d,region,gender,condition)
> score<-summarize(dg,n=n(),mean=mean(score),sd=sd(score))
> score
Source: local data frame [16 x 6]
Groups: region, gender [?]
region gender condition n mean sd
<fctr> <fctr> <fctr> <int> <dbl> <dbl>
1 East female A 14 52.92857 5.876476
2 East female B 7 61.00000 6.403124
3 East female C 13 71.38462 7.555776
4 East female D 10 79.90000 11.666190
5 East male A 6 58.33333 11.039324
6 East male B 13 60.92308 7.365025
7 East male C 7 68.14286 12.266874
8 East male D 10 82.10000 7.445356
9 West female A 8 57.37500 11.807231
10 West female B 10 59.60000 11.834038
11 West female C 9 60.33333 12.649111
12 West female D 9 59.22222 7.446103
13 West male A 12 62.25000 10.771385
14 West male B 10 55.90000 12.653063
15 West male C 11 61.72727 18.461262
16 West male D 11 59.45455 6.408801
> EG<-subset(score,region=="East")
> library(ggplot2)
> eg<-ggplot(EG)
> eg+
+ geom_bar(aes(x=gender,y=mean,fill=condition),
+ stat="identity",
+ position="dodge")+
+ geom_errorbar(aes(x=gender,
+ ymin=mean-sd/sqrt(n),
+ ymax=mean+sd/sqrt(n),
+ group=gender),
+ width=0.25,
+ position=position_dodge(0.9))
※1
> egb<-ggplot(EG,aes(x=condition,y=mean,fill=gender))+
+ geom_bar(position="dodge",stat="identity")+
+ geom_errorbar(aes(ymin=mean-sd/sqrt(n),ymax=mean+sd/sqrt(n)),
+ position=position_dodge(0.9),width=0.25)
> egb
> ggsave("egb")
Error: Unknown graphics device ''
※2
> WG<-subset(score,region=="West")
> wg<-ggplot(WG)
> wgb<-ggplot(WG,aes(x=condition,y=mean,fill=gender))+
+ geom_bar(position="dodge",stat="identity")+
+ geom_errorbar(aes(ymin=mean-sd/sqrt(n),ymax=mean+sd/sqrt(n)),
+ position=position_dodge(0.9),width=0.25)
> wgb
> wgb