As usual @nirgrahamuk has the right solution. My example below shows how to use it in your case:
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
library(ggplot2)
stomata = data.frame(
Control_ABA = c(rep("DiH2O (Control)",3),rep("ABA",3)),
Solution=rep(c("CaCI2","DiH2O","EGTA"),2),
Mean= 1:6,
SE = (1:6)/10
)
stomata
#> Control_ABA Solution Mean SE
#> 1 DiH2O (Control) CaCI2 1 0.1
#> 2 DiH2O (Control) DiH2O 2 0.2
#> 3 DiH2O (Control) EGTA 3 0.3
#> 4 ABA CaCI2 4 0.4
#> 5 ABA DiH2O 5 0.5
#> 6 ABA EGTA 6 0.6
my_labels1 <-c("DiH2O (Control)"=expression(DiH[2]*O),"ABA" = "ABA")
my_labels2 <-c("CaCI2"=expression(CaCI[2]),"DiH2O"=expression(DiH[2]*O),"EGTA"="EGTA")
stomata_plt<-ggplot(data=stomata, aes(x=Control_ABA, y=Mean, fill=Solution))+
geom_bar(stat="identity", color="black", position=position_dodge())+
geom_text(aes(label="N = 5"), position=position_dodge(width=0.9), vjust=-3, size = 3)+
geom_errorbar(aes(ymin=Mean-SE, ymax=Mean+SE), width=.2, position=position_dodge(.9))+
theme_minimal() +
scale_y_continuous("Mean stomata opening ± SE (µm)") +
scale_x_discrete(labels=my_labels1) +
scale_fill_discrete(labels=my_labels2) +
theme(axis.title.x = element_blank())+
theme(
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank())+
theme(axis.text = element_text(size = 14))+
theme(axis.title.y = element_text(size = 14))+
theme(axis.line = element_line(size = 0.5, colour = "black", linetype=1))+
theme(legend.text=element_text(size=14))
stomata_plt
Created on 2021-11-19 by the reprex package (v2.0.0)
