I am trying to convert the y-axis of a bar-chart to a logarithmic scale (I.e. logarithmic distance between each ticks).
Some dummy data:
DF <- data.frame(num=c(1,2,3),label=c("a","b","c"))
I've tried the following examples:
p <- ggplot(data=DF,aes(x=label,y=num)) + geom_bar() +
scale_y_continuous(trans = 'log10',
breaks=trans_breaks("log10",function(x) 10^x),
labels=trans_format("log10",math_format(10^.x)))
This only log transforms labels, but not ticks:
p <- ggplot(data=DF,aes(x=label,y=num)) + geom_bar() + coord_trans(y="log10")
This doesn't plot anything at all:
p <- ggplot(data=DF,aes(x=label,y=num),y="log")
No luck either
I have also read the 0.9 transition guide , but that does not seem to work either.
EDIT:
I forgot to include one example I tried:
p <- ggplot(data=DF,aes(x=label,y=num)) + geom_bar() + scale_y_log10()
Which produces the following warning:
Warning message: In pretty(trans(x), n, ...) : NaNs produced
labels
arg inscale_y_log10
. – Richie Cotton