average y values bar graph with error bars

I've done an anova and now I want to display my data. I looking at flight initiation distance in squirrels at different levels of human activity. I have three levels of humans activity (L, M, H) and 20ish inputs of flight initiation at each of those levels of activity. I want to create a bar graph of the average flight initiation distance at the levels of activity and I want to add in standard error bars. Any ideas for the code?

Maybe try geom_ribbon?

you can look at this site for an example of what i think you want

http://www.sthda.com/english/wiki/ggplot2-error-bars-quick-start-guide-r-software-and-data-visualization

Here is some code i used. The data frame (ANPP_means) has the meanANPP, Year, SE and there is a treatment group as well (so there will be a set of bar charts for each year on one graph, you can delete the fill= if you do not have treatments)
ggplot(ANPP_means, aes(x = Year , y = meanANPP, fill=trt_label)) +
geom_bar(stat = "identity", color = "black", position=position_dodge()) +
geom_errorbar(aes( ymin = meanANPP-SE, ymax = meanANPP+SE), width=.2,
position=position_dodge(.9)) +
theme_bw()

Thanks! My bar graph kind of messed up the order in which I want the bars (it showed medium, low , high) do you know what I could add to the code to choose the order of the bars?

If the x variable is character the barplot will use alphabetical. If a factor it will use the levels. I suspect you have a factor since high is at the end. You can change the levels. first look at levels(variable) to see the order. Then you can reorder using code like this
dataset$varname <- factor(dataset$varname, levels=c( "low", "medium", "high").

This is my code so far:
ggplot(df.summary, aes(Anthropogenic_Activity, FID_mean)) +
geom_col(fill = "blue", color = "black") +
geom_errorbar(aes(ymin = FID_mean-sd, ymax = FID_mean+sd), width = 0.2)+
df.summary$Anthropogenic_Activity=factor(df.summary$Anthropogenic_Activity,levels=c("L","M","H"))

But I keep getting the error "could not find function "+<-", what do you think the issue is?

Never mind! I realized you meant do that code on it's own before hand. It worked!!! Thanks!

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.