I would like to have bars and errorbars for this data
I managed to get the bars with:
ggplot(FCDreach_global_mod, aes(x = as.factor(t3-t2), y = 1-value, fill=as.factor(t2-t1) )) +
geom_bar(stat = "identity" )
However I don't know how to draw the errorbars. I tried geom_errorbar()
but couldn't get it work.
When drawing line plots I would use:
stat_summary(fun.data=mean_cl_normal, geom="errorbar")
but this does not seem to work correctly with geom_bar()
I tried this:
ggplot(FCDreach_global_mod, aes(x = as.factor(t3-t2), y = 1-value, fill=as.factor(t2-t1) ) ) +
stat_summary(fun.y=mean,geom="bar")+
stat_summary(fun.data=mean_cl_normal,geom="errorbar", width=0.5)
and the breaks on the y
looked quite different compared to the ones I got with geom_bar(stat = "identity" )
. The size of the bars is the same, but something weird happens with the y scale.
stat_summary:
EDIT: the desired output is to show the equivalent of this plot in a barplot, of course excluding the x
axis and placing t3-t2
on x
which I obtain by:
ggplot(FCDreach_global_mod, aes(x=roundedRealNumVehicles/2, y=1-value, colour=as.factor(t3-t2), lty=as.factor(t2-t1)) ) +
stat_summary( fun.y=mean, geom="line" ) +
stat_summary(fun.data=mean_cl_normal,geom="errorbar", width=0.5)