I have a summary data set with means of accuracy (Freq) and standart deviations (sd) that looks like this:
> sum = summarySE(df, measurevar="Freq", groupvars=c("Block","Reward", "Congruency"))
> sum
Block Reward Congruency N Freq sd se ci
1 CSRA 0 0 25 92.81094 5.696302 1.139260 2.351318
2 CSRA 0 1 25 89.15566 9.163108 1.832622 3.782345
3 CSRA 1 0 25 87.58630 13.034372 2.606874 5.380324
4 CSRA 1 1 25 84.92784 13.431737 2.686347 5.544349
5 MID 0 0 25 91.94928 7.562742 1.512548 3.121747
6 MID 0 1 25 83.93017 9.187526 1.837505 3.792424
7 MID 1 0 25 89.00725 6.790402 1.358080 2.802940
8 MID 1 1 25 84.19499 12.045129 2.409026 4.971985
9 NEUT 0 0 25 87.97193 8.286820 1.657364 3.420631
10 NEUT 0 1 25 80.87517 10.945678 2.189136 4.518154
11 NEUT 1 0 25 87.97193 8.286820 1.657364 3.420631
12 NEUT 1 1 25 80.87517 10.945678 2.189136 4.518154
13 SRA 0 0 25 93.97101 6.312160 1.262432 2.605532
14 SRA 0 1 25 90.19947 8.873230 1.774646 3.662689
15 SRA 1 0 25 86.89789 10.910052 2.182010 4.503448
16 SRA 1 1 25 81.42151 12.470161 2.494032 5.147429
and the barplot for it:
sum$Reward <- revalue(sum$Reward , c("1"="No Reward", "0"="Reward"))
sum$Block <- revalue(sum$Block , c("CSRA"="C-SRA"))
sum$Congruency <- revalue(sum$Congruency , c("1"="Incongruent", "0"="Congruent"))
ggplot(sum,
aes(x=Congruency, y=Freq, group=Block,
ymax=Freq+se, ymin=Freq-se)) +
geom_bar(stat="identity", position = "dodge", aes(fill=Block)) +
facet_wrap( ~ Reward) +
geom_errorbar(position=position_dodge(width=0.7),
width=0.0, size=0.5, color="black") +
labs(x = "Block",
y = "Acuracy [%]") +
theme_bw() +
theme(panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(colour = "grey50"),
plot.title = element_text(size = rel(1.5),
face = "bold", vjust = 1.5),
axis.title = element_text(face = "bold"),
legend.key.size = unit(0.4, "cm"),
legend.key = element_rect(fill = "black"),
axis.title.y = element_text(vjust= 1.8),
axis.title.x = element_text(vjust= -0.5)) +
coord_cartesian(ylim = c(70, 100))+
scale_fill_manual(name="Condition", # Legend label, use darker colors
values=c("#E69F00", "#56B4E9", "#F0E442", "#009E73")) +
theme(panel.grid.major = element_blank(), text = element_text(size=15), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"))
As you see, I have two small barplots implemented in one bigger one: Reward and No Reward. What I want to do is to change them with places, i.e., to swap them (first No Reward and then Reward). Thus, I am trying to change the order a stack of facets (Reward vs No Reward) rather than changing the order of facets themselves (C-SRA vs SRA vs MID vs Netral). Is there any way of doing it in the ggplot script or I should do it outside the ggplot script?