Main issue: I want to display the data from 0 to 1.0 as an upward bar (starting from 0) but do not want the intervals to be equally spaced but log spaced.
I am tryi
Here's a bit of hacking to show what happens if you try to get bars that start at zero on a log scale. I've used geom_segment
for illustration, so that I can create "bars" (wide line segments, actually) extending over arbitrary ranges. To make this work, I've also had to do all the dodging manually, which is why the x
mapping looks weird.
In the example below, the scale goes from y=1e-20 to y=1. The y-axis intervals are log scaled, meaning that the physical distance from, say 1e-20 to 1e-19 is the same as the physical distance from, say, 1e-8 to 1e-7, even though the magnitudes of those intervals differ by a factor of one trillion.
Bars that go down to zero can't be displayed, because zero on the log scale is an infinite distance below the bottom of the graph. We could get closer to zero by, for example, changing 1e-20
to 1e-100
in the code below. But that will just make the already-small physical distances between the data values even smaller and thus even harder to distinguish.
The bars are also misleading in another way, because, as @hrbrmstr pointed out, our brains treat distance along the bar linearly, but the magnitude represented by each increment of distance along the bar changes by a factor of 10 about every few millimeters in the example below. The bars simply aren't encoding meaningful information about the data.
ggplot(data=df, aes(x=as.numeric(snp) + 0.3*(as.numeric(type) - 1.5),
y=mean, colour=type)) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.3) +
geom_segment(aes(xend=as.numeric(snp) + 0.3*(as.numeric(type) - 1.5),
y=1e-20, yend=mean), size=5) +
scale_y_log10(limits=c(1e-20, 1), breaks=10^(-100:0), expand=c(0,0)) +
scale_x_continuous(breaks=1:6, labels=LETTERS[1:6])
If you want to stick with a log scale, maybe plotting points would be a better approach:
pd = position=position_dodge(.5)
ggplot(data=df, aes(x=snp,y=mean,fill=type))+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se, colour=type), width=.3, position=pd) +
geom_point(aes(colour=type), position=pd) +
scale_y_log10(limits=c(1e-7, 1e-5), breaks=10^(-10:0)) +
annotation_logticks(sides="l")