alphastats<-summarySE(map, measurevar="shannon", groupvars=c("age_class"))
age_class N shannon sd se ci
1 Non_Smoker 66 5.473424 0.4152997 0.05111986 0.1020934
2 Old_Smoker 47 5.271223 0.6046414 0.08819601 0.1775294
3 Young_Smoker 17 5.324977 0.8682071 0.21057116 0.4463909
Hi, so I'm trying to add error bars to a ggplot2 boxplot in R. I have the above data frame created with the necessary standard error data for each of my three groups.
ggplot() +
geom_boxplot(data=map, aes(x=age_class, y=shannon, fill=age_class), na.rm= TRUE ) +
theme_bw() +
geom_jitter(data=map, aes(x=age_class, y=shannon), position=position_jitter(width=0.1)) +
labs(x="Group", y="Shannon Value") +
guides(fill=guide_legend(title="Group Type")) +
annotate("text", x=0.75, y=3.5, size=3, label=paste0("p-value =",alpha_p_round)) +
geom_errorbar(data=alphastats, aes(ymin=shannon-se, ymax=shannon+se))
When I attempt to add the error bars through gg_errorbar(), I get the error:
"Error in eval(expr, envir, enclos) : object 'x' not found
In addition: Warning messages:
1: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
2: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf
3: In min(diff(sort(x))) : no non-missing arguments to min; returning
Inf
Could anyone help me in figuring out what I'm doing wrong?
map
andalpha_p_round
are not defined. – Maurits Evers