I'm creating a series of figures for some vegetation survey data and I'm coming up against a frustrating barrier in ggplot2. I managed to figure out how to make a figure with all the elements I want using:
ISI_summary<-anovadata %>% group_by(Site) %>% summarise(mean_ISI= mean(ISI), sd_ISI= sd(ISI), n_ISI= n(), se_ISI= sd(ISI)/sqrt(n())) ISIPlot<-ggplot(ISI_summary, aes(Site, mean_ISI))+ geom_col(color= "gray20", fill="seagreen3")+ geom_errorbar(aes(ymin=mean_ISI-se_ISI, ymax=mean_ISI+se_ISI), width=0.2)+ geom_text(label=c("b","a","a","a","a","b","a"), aes(y=mean_ISI+se_ISI, x=Site), vjust=-0.5, size=5)+ ylim(0,2.5) ISIfigure<-ISIPlot + labs(y="Mean ISI ± SE", x="Site")
However when I try to replicate this figure using a different variable:
Rich_summary<-anovadata %>% group_by(Site) %>% summarise(mean_rich= mean(rich), sd_rich= sd(rich), n_rich= n(), se_rich= sd(rich/sqrt(n())) RichPlot<-ggplot(Rich_summary, aes(Site, mean_rich)) + geom_col(color= "gray20", fill="steelblue3") + geom_errorbar(aes(ymin=mean_rich-se_rich, ymax=mean_rich+se_rich), width=0.2) + geom_text(label=c("a","ab","abc","c","bc","bc","ab"), aes(y=mean_rich+se_rich, x=Site), vjust=-0.5, size=5) Richfigure<-RichPlot + labs(y="Mean Total Species Richness ± SE", x="Site")
I get the error "Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?"
I'm not sure what's happening here. I copied the text from the first figure exactly, just replacing the "ISI" variable with the "rich" variable. Can anyone offer some advice? Thank you