I have a dataframe that looks like this:
structure(list(type = c("aerial", "aerial", "aerial", "aerial",
"TLAcmeth", "TLAcmeth", "TLAcmeth", "TLAcmeth", "TLAmeandaily",
"TLAmeandaily", "TLAmeandaily", "TLAmeandaily"), season = c("Fall",
"Spring", "Summer", "Winter", "Fall", "Spring", "Summer", "Winter",
"Fall", "Spring", "Summer", "Winter"), TotalEffort = c(190673.543181818,
218904.879166667, 203450.11969697, 56238.5424242424, 268342.820454545,
285751.855555556, 345593.292424242, 98186.1393939394, 231709.359979371,
240226.110903571, 297768.291682299, 89965.0324616366), TotalVariance = c(492915253.434218,
568040077.261171, 647316950.988574, 98882407.0742865, 1809446616.57252,
1459917672.26073, 2412306298.47967, 249200347.968292, 690088788.630394,
219887023.857297, 762532238.93411, 184763903.639171), STE = c(22201.6948324721,
23833.5913630567, 25442.424235685, 9943.96334839819, 42537.5906296128,
38208.8690261924, 49115.2348918304, 15786.0808299049, 26269.5410814577,
14828.588060139, 27613.9862919882, 13592.7886630806)), row.names = c(NA,
-12L), class = "data.frame")
When I go to plot these data using this ggplot code:
ggplot(E_StE, aes(x = season, y = TotalEffort, fill = type)) +
geom_bar(stat = "identity", position = "dodge", color = "black") +
scale_y_continuous(name = "Estimated Effort (h)", expand = c(0, 0)) +
geom_errorbar(aes(ymin = TotalEffort-STE, ymax = TotalEffort+STE), position = "dodge", width = 0.2) +
xlab("Season")
I get this output:
What is wrong with my code where I all of my error bars are on one bar not their assigned bar?
>Solution :
It’s because you changed the width of the error bars. If you take the width out you get
geom_errorbar(aes(ymin = TotalEffort-STE, ymax = TotalEffort+STE),
position ="dodge")

Sp you can set the width of the dodging to be different than the width of the bars:
geom_errorbar(aes(ymin = TotalEffort-STE, ymax = TotalEffort+STE),
position = position_dodge(width=.9), width=.2)

