ONKELINX, Thierry
2007-Jul-25 09:37 UTC
[R] Ggplot2 equivalent of axis and problem with log scale
Dear useRs, Recently I've discorved ggplot2 and I must say that I really like it, although the documentation still is a working in progress. My first question: How can I change the position of the labels and the text of the labels? With a basic plot I would use axis(2, at position.of.the.ticks, labels = text.at.the.ticks). Could someone provide me with an example of how to do this with ggplot2? The second question is probably a little bug. If I plot the y-axis in log10 scale then geom_errorbar still plot the values in the original scale. See the example below. The second plot is what I would suspect when plotting the first graph. library(ggplot2) df <- data.frame(x = rep(1:10, 10), y = rnorm(100)) df$y <- 10 ^ (df$x + df$y) df <- cbind(df, predict(lm(I(log10(y)) ~ x, data = df), interval = "c")) df[, 3:5] <- 10 ^ df[, 3:5] ggplot(data = df, aes(x = x, y = y)) + geom_point() + scale_y_log10() + geom_line(aes(y = fit)) + geom_errorbar(aes(min = lwr, max = upr)) ggplot(data = df, aes(x = x, y = y)) + geom_point() + scale_y_log10() + geom_line(aes(y = fit)) + geom_errorbar(aes(min = log10(lwr), max log10(upr))) Thanks, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx op inbo.be www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney
hadley wickham
2007-Jul-25 14:55 UTC
[R] Ggplot2 equivalent of axis and problem with log scale
On 7/25/07, ONKELINX, Thierry <Thierry.ONKELINX at inbo.be> wrote:> Dear useRs, > > Recently I've discorved ggplot2 and I must say that I really like it, > although the documentation still is a working in progress. > > My first question: How can I change the position of the labels and the > text of the labels? With a basic plot I would use axis(2, at > position.of.the.ticks, labels = text.at.the.ticks). Could someone > provide me with an example of how to do this with ggplot2?Have a look at scale_continous - in particular the breaks and labels arguments (although I haven?t tested them much yet). You need + scale_x_continuous() and + scale_y_continuous() as appropriate.> The second question is probably a little bug. If I plot the y-axis in > log10 scale then geom_errorbar still plot the values in the original > scale. See the example below. The second plot is what I would suspect > when plotting the first graph.Yes, that's a bug - I`ll try and get it fixed in the next version. Thanks, Hadley