From the very useful transition guide, I understand that the default
breaks have changed for scale_*_log10(). If I want the old behavior,
which I do, I need to write something like,
scale_x_log10(breaks = trans_breaks(’log10’, function(x) 10^x),
labels = trans_format(’log10’, math_format(10^.x)))
which I don't find very convenient. Is there a shortcut?
Also, I find the minor breaks --half-way in between the major
breaks--, quite misleading / hard to interpret in ggplot2, being used
to seeing log-scales as in
http://upload.wikimedia.org/wikipedia/commons/b/b5/Logarithmic_Scales.svg
How do I get more customary minor breaks without too much hassle?
I'm unfamiliar with the new syntax, have I missed something?
Many thanks,
baptiste
Best,
b.
On 9 February 2012 21:59, baptiste auguie
scale_x_log10old <- function(...) {
scale_x_log10(breaks = trans_breaks(’log10’, function(x) 10^x),
labels = trans_format(’log10’, math_format(10^.x)), ...)
}
?
> Also, I find the minor breaks --half-way in between the major
> breaks--, quite misleading / hard to interpret in ggplot2, being used
> to seeing log-scales as in
> http://upload.wikimedia.org/wikipedia/commons/b/b5/Logarithmic_Scales.svg
The minor breaks should be half-way in between the major breaks in
data space, not in transformed space. Is that not what you're seeing?
> How do I get more customary minor breaks without too much hassle?
What are the more customary breaks?
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
Best to file a bug report - there is no guarantee I will remember to
follow up on a line note. (And the ref should be to ?scales::trans.
On 10 February 2012 02:39, Hadley Wickham <had...@rice.edu> wrote:
> On Thu, Feb 9, 2012 at 2:59 AM, baptiste auguie
> <baptist...@googlemail.com> wrote:
>> Hi,
>>
>> From the very useful transition guide, I understand that the default
>> breaks have changed for scale_*_log10(). If I want the old behavior,
>> which I do, I need to write something like,
>>
>> scale_x_log10(breaks = trans_breaks(’log10’, function(x) 10^x),
>> labels = trans_format(’log10’, math_format(10^.x)))
>>
>> which I don't find very convenient. Is there a shortcut?
>
> scale_x_log10old <- function(...) {
> scale_x_log10(breaks = trans_breaks(’log10’, function(x) 10^x),
> labels = trans_format(’log10’, math_format(10^.x)), ...)
> }
>
> ?
Could this be included in ggplot2? In fact, since scale_x_log10() now
appears a little redundant, given the more general
scale_continuous(trans=""), could we make it a convenience function
that selects either style?
scale_x_log10 <- function(..., style=c("original", "transformed")) {
style <- match.arg(style)
breaks <- switch(style, "original"=NULL,
"transformed"=trans_breaks(’log10’, function(x) 10^x))
labels <- switch(style, "original"=NULL,
"transformed"=trans_format(’log10’, math_format(10^.x)))
dots <- list(...)
params <- modifyList(dots, list(trans = log10_trans(),
breaks=breaks, labels=labels))
do.call(scale_x_continuous, params)
}
set.seed(123)
DF <- data.frame(x = rlnorm(1000, m = 1, sd = 0.2), y=rnorm(1000))
p <- ggplot(DF, aes(x = x, y=y)) + geom_point()
library(gridExtra)
grid.arrange(
p + scale_x_continuous(trans = "log10"),
p + scale_x_log10(style="original"), # equivalent to the previous one
p + scale_x_log10(style="transformed")) # old style
In all of the above the minor_breaks are in the midposition between
breaks; in fact I was not successful in changing them at all with
minor_breaks=trans_breaks("log10", function(x) 10^x, n=100)
What I consider the most common case for minor breaks is shown here
(first few graphs anyway): http://en.wikipedia.org/wiki/Semi-log_plot
Schematically,
| : : : ::::| : : : ::::| : : : ::::|
1 10 100 1000
Thanks,
baptiste
> scale_x_log10old <- function(...) {Could this be included in ggplot2? In fact, since scale_x_log10() now
> scale_x_log10(breaks = trans_breaks(’log10’, function(x) 10^x),
> labels = trans_format(’log10’, math_format(10^.x)), ...)
> }
>
> ?
appears a little redundant, given the more general
scale_continuous(trans=""), could we make it a convenience function
that selects either style?
scale_x_log10 <- function(..., style=c("original", "transformed")) {
Schematically,
| : : : ::::| : : : ::::| : : : ::::|
1 10 100 1000
qplot(10^(1:6), 10^(1:6)) + scale_x_log10(breaks = 10^(1:6),
minor_breaks = log(c(sapply(x, function(x) seq(0, x, x/10))), 10)
I think the inside tick is useful and will appear with the improvement
of positional guides.
As for the original and transformed spaces, see also this issue:
https://github.com/hadley/ggplot2/issues/373
kohske
2012/2/10 Winston Chang <winsto...@gmail.com>:
--
--
Kohske Takahashi <takahash...@gmail.com>
Research Center for Advanced Science and Technology,
The University of Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html
I like that idea! I think the details need a little tweaking (so you
can still specify breaks and labels in the same way as other scales),
but smart details would be better. I don't think that needs much
tweaking:
breaks <- breaks %||% switch(style, "trans" = trans_breaks(’log10’,
function(x) 10^x))
labels <- labels %||% switch(style, "trans" = trans_format(’log10’,
math_format(10^.x)))
(I'd prefer adding breaks and labels to using your perfectly valid
technique of modifying dots because it makes tracebacks easier to
understand if something goes wrong).
And maybe style = c("raw", "trans") or c("data", "trans"). Not sure.
> In all of the above the minor_breaks are in the midposition between
> breaks; in fact I was not successful in changing them at all with
>
> minor_breaks=trans_breaks("log10", function(x) 10^x, n=100)
That may be a bug. Would you mind filing a bug report?
> What I consider the most common case for minor breaks is shown here
> (first few graphs anyway): http://en.wikipedia.org/wiki/Semi-log_plot
>
> Schematically,
>
> | : : : ::::| : : : ::::| : : : ::::|
> 1 10 100 1000
I'm certainly open to better defaults, but it's really hard to get
them to work in a wide variety of situations. e.g. what should the
breaks and minor breaks look like if the range is 2-5 ? Some test
cases would be really useful (and I think if someone really spent time
thinking about this it would be publishable - especially if you could
extend to other non-linear scales)