I'm new using R and ggplot library, and I'm trying to build a bar chart with an error bar, like this:
pd <- position_dodge(0.80)
ggplot(aqp1) + geom_bar( aes(x=Type, y=Error, fill=Set, colour=Set, group=Set), width=0.75, stat="identity", alpha=1, position=pd)
+ geom_errorbar( aes(x=Type, ymin=Error,ymax=Max.Error, colour=NULL, group=Set), position=pd, width=0.1, colour="black", alpha=1, size=0.1)
+ theme_light() + labs(title="", x="Sizes", y="Relative error (%)")
The only thing is that I would like logscale the y-axis, so I tried using the scale_y_log10
function:
ggplot(aqp1) + geom_bar( aes(x=Type, y=Error, fill=Set, colour=Set, group=Set), width=0.75, stat="identity", alpha=1, position=pd)
+ geom_errorbar( aes(x=Type, ymin=Error,ymax=Max.Error, colour=NULL, group=Set), position=pd, width=0.1, colour="black", alpha=1, size=0.1)
+ theme_light() + labs(title="", x="Sizes", y="Relative error (%)")
+ scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
But I have a bizarre result, where the errorbar has another scale, different from the bar chart.
How can I fix this? I tried using + ylim(10^-2, 10^1)
but it doesn't work.