I have read quite a bit and have tried following multiple examples from this post below but I am still getting an error. Annotating text on individual facet in ggplot2
Maybe I am making a simple mistake that I cannot see ?
Here is one iteration of my code:
ann_text <- data.frame(Gender = factor(c("Female","Male"),levels=c("Female","Male")) ,lab = c(captionF,captionM))
##
g<-ggplot(dat.czm.annot.otu,aes_string(x=condition2,y="counts"))+geom_boxplot(alpha=0.8,outlier.size = -1)+
facet_wrap(~Gender)+
# geom_point(aes(fill=Diet),size = 3, shape = 21,position = position_jitterdodge(jitter.width = 0.02,jitter.height = 0))+
geom_point(aes(fill=Gender),size = 3, shape = 21,position = position_jitterdodge(jitter.width = 0.02,jitter.height = 0))+
guides(fill=FALSE)+
#annotate("text",x=c(1.5,1.5),y=c(0.7*ymax,0.8*ymax),label=c(captionM,captionF))+
ggtitle(otu_name_clean)+
ylab("proportion")+
labs(subtitle=paste(subset,"subset"),caption=caption)+
theme(plot.title = element_text(size = 18, face = "bold"))+
theme(axis.text=element_text(size=14),
axis.title=element_text(size=14)) +
theme(legend.text=element_text(size=14),
legend.title=element_text(size=14)) +
theme(strip.text.x = element_text(size = 14))
g+geom_text(data = ann_text,label=ann_text$lab)
Here is the error that I'm getting:
Error in FUN(X[[i]], ...) : object 'Time' not found
Time is condition2
, that is the x variable for the boxplots, specified in aes_string
.
Any help is appreciated. thanks