[R] Ggplot2 equivalent of axis and problem with log scale

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Wed Jul 25 11:37:44 CEST 2007


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



More information about the R-help mailing list