How to override ggplot2's axis formatting?
Posted
by Richie Cotton
on Stack Overflow
See other posts from Stack Overflow
or by Richie Cotton
Published on 2010-05-25T17:20:04Z
Indexed on
2010/05/25
17:41 UTC
Read the original article
Hit count: 296
When you choose a log scale, ggplot2 formats the breaks like 10^x. I'd like it to not do that. For example, the code below should display a graph with ticks at 1, 2, 5 etc, not 10^0, 10^0.3, 10^0.69 etc.
library(ggplot2)
dfr <- data.frame(x = 1:100, y = rlnorm(100))
breaks <- as.vector(c(1, 2, 5) %o% 10^(-1:1))
p1 <- ggplot(dfr, aes(x, y)) + geom_point() + scale_y_log10(breaks = breaks)
print(p1)
I guess that adding a formatter
argument to scale_y_log10
would do the trick, but I'm not sure what to put in the argument, or where the options might be documented.
© Stack Overflow or respective owner