I mean axis labels like what you get in the call to base graphics below.
junk<-data.frame(x=-3:2)
junk$y<- exp(junk$x^2)
# This labels the y axis in a way that a non-statistician can understand:
plot( y~ x, log="y", data=junk)
require(ggplot2)
# This labels the y axis in a way that only someone with mathematical
# training can understand:
print( ggplot(data=junk, aes(x=x, y=y)) + geom_point() + scale_y_log())
Thanks for any insights
Jacob Wegelin
I would submit that your y-axis is misleading because it has equally
(linearly) spaced tick marks and nonlinear axis labels, and therefore
would likely confuse rather than edify a layperson. (I don't know many
non-mathematicians/scientists who can mentally interpolate values such
as 125 or 500 on such scales.) Here are a couple of ways to get what
you want, but I prefer the exponential labels because at least they
clarify that each break represents a power of 10. (BTW, this assumes
ggplot2-0.9.0 with the scales package loaded.)
library('ggplot2')
library('scales')
ggplot(junk, aes(x = x, y = y)) + geom_point() +
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x))
ggplot(junk, aes(x = x, y = y)) + geom_point() +
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x)))
trans_breaks() and trans_format() are functions from the scales
package, as is math_format(). Functions that end in _breaks in the
scales package are meant to be used in conjunction with the breaks =
argument in a scale_*() function call, whereas functions that end in
_format are meant to be used with the labels = argument. The _format()
functions in the scales package replace and generalize the formatter =
argument in previous versions of ggplot2.
Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
> ggplot(junk, aes(x = x, y = y)) + geom_point() +
+ scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x))
Error in match.fun(get(".transform", .))(values) :
Non-numeric argument to mathematical function
> ggplot(junk, aes(x = x, y = y)) + geom_point() +
+ scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
+ labels = trans_format("log10", math_format(10^.x)))
Error in match.fun(get(".transform", .))(values) :
Non-numeric argument to mathematical function
> sessionInfo()
R version 2.14.2 Patched (2012-02-29 r58604)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid splines stats graphics grDevices utils datasets methods base
other attached packages:
[1] scales_0.2.0 ggplot2_0.9.0 proto_0.3-9.2 reshape_0.8.4 plyr_1.6 nlme_3.1-103
loaded via a namespace (and not attached):
[1] colorspace_1.1-0 dichromat_1.2-4 digest_0.5.1 lattice_0.20-0 munsell_0.3 psych_1.1.11 RColorBrewer_1.0-5 stringr_0.5
[9] tools_2.14.2
What's wrong?
Jacob Wegelin
D.