Just wondering if there was any update on the possibility of plotting
log-scaled axes without scientific notations, and with breaks that are
pretty on the original scale, as in these threads:
This is my current solution, which could probably be tweaked a bit:
the guts are mostly drawn from the example in ?axTicks which replicates
the internal calculations that base R does for pretty log axis ticks ...
lsc <- function(limit,...) {
get_axp <- function(x) 10^c(ceiling(x[1]), floor(x[2]))
## mimic par("yaxs")=="i"
usr.i <- log10(limit)
(aT.i <- axTicks(side=2, usr=usr.i,
axp=c(get_axp(usr.i), n=3), log=TRUE))
scale_y_log10(breaks=aT.i,labels=format(aT.i,scientific=FALSE,
trim=TRUE, drop0trailing=TRUE))
}
??
Ben Bolker
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk4LabkACgkQc5UpGjwzenNnvgCglhbA+HdQdcR4yU3gPztgDcn7
d6wAmwb+c7X1mBmVFtISYE/43dZhWvIo
=epB2
-----END PGP SIGNATURE-----
Yes, this will be the default in the next version of ggplot2.
If you want to try out the latest version, it's not too difficult to do:
install.packages("devtools")
library(devtools)
install_github("devtools") # get latest dev version of devtools
# may need to restart R here (not sure)
install_github("scales") # get new scales package
dev_mode() # switch to dev mode so you don't kill your existing install
install_github("ggplot2", branch = "develop")
library(ggplot2)
qplot(mpg, wt, data = mtcars) + scale_x_log10()
(you'll need R 2.13, and if on windows, you'll need to have installed Rtools)
If it doesn't work, please let me know so I can fix the instructions -
I would like to make it easier for people to try out the development
version.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
On 6/29/2011 11:20 AM, Hadley Wickham wrote:
>> Just wondering if there was any update on the possibility of plotting
>> log-scaled axes without scientific notations, and with breaks that are
>> pretty on the original scale, as in these threads:
>>
>> http://groups.google.com/group/ggplot2/browse_thread/thread/658aac9db56065b/fcf69c35ae0898e4?lnk=gst&q=scale_y_log10+breaks+pretty#fcf69c35ae0898e4
>>
>> http://groups.google.com/group/ggplot2/browse_thread/thread/f0a5d89133c600ed/3a820d0ab05e5d8d?lnk=gst&q=scale_y_log10+formatter#3a820d0ab05e5d8d
>
> Yes, this will be the default in the next version of ggplot2.
>
> If you want to try out the latest version, it's not too difficult to do:
And if you want a hack that works with the current version (and is
pretty much guaranteed to not work with the next one):
TransLog10I <- Trans$new("log10I", "log10",
function(x) 10^x, function(x) format(10^x, scientific=FALSE))
ggplot(...) +
... +
scale_y_continuous(trans="log10I")
> install.packages("devtools")
> library(devtools)
>
> install_github("devtools") # get latest dev version of devtools
> # may need to restart R here (not sure)
> install_github("scales") # get new scales package
>
> dev_mode() # switch to dev mode so you don't kill your existing install
> install_github("ggplot2", branch = "develop")
>
> library(ggplot2)
> qplot(mpg, wt, data = mtcars) + scale_x_log10()
>
> (you'll need R 2.13, and if on windows, you'll need to have installed Rtools)
>
> If it doesn't work, please let me know so I can fix the instructions -
> I would like to make it easier for people to try out the development
> version.
>
> Hadley
>
>
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
R version 2.13.0 (2011-04-13)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> install.packages("devtools")
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.13
trying URL 'http://cran.parentingamerica.com/bin/windows/contrib/2.13/devtools_0.1.zip'
Content type 'application/zip' length 60853 bytes (59 Kb)
opened URL
downloaded 59 Kb
package 'devtools' successfully unpacked and MD5 sums checked
The downloaded packages are in
C:\Users\pwhaite\AppData\Local\Temp\RtmpA0eAUh\downloaded_packages
> library(devtools)
> install_github("devtools")
Installing devtools from hadley
Error in unzip(src, list = TRUE) :
zip file 'C:\Users\pwhaite\AppData\Local\Temp\RtmpA0eAUh/hadley-devtools.zip' cannot be opened
In addition: Warning messages:
1: running command 'wget --quiet https://nodeload.github.com/hadley/devtools/zipball/master -O C:\Users\pwhaite\AppData\Local\Temp\RtmpA0eAUh/hadley-devtools.zip' had status 1
2: In download.file(zip_url, src, method = "wget", quiet = TRUE) :
download had nonzero exit status
> --
> 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
Great! I'm trying to make things more explicit, which does mean a bit
more typing, but I think the tradeoff is worth it.
I would like to write a function to do the formatting
> I want. I tried this:
> exp_format <- function() {
> function(x) {
> trans_format("log10",math_format(format=scientific_format(x,digits=2,...)))
> }
> }
You weren't using x in quite the right place. You still need to call
the function that trans_format produces:
exp_format <- function() {
function(x) {
exponent <- math_format(format = scientific_format(digits = 2))
trans_format("log10", exponent)(x)
}
}
Or you can get rid of x altogether:
exp_format <- function() {
exponent <- math_format(format = scientific_format(digits = 2))
trans_format("log10", exponent)
}
qplot(c(1,10),c(1,10)) +
scale_y_log10(labels = exp_format()) +
scale_x_log10(labels = exp_format())