Fix back-transformation of ranges in coords #2821
The key to fixing these bugs is to recognize that the
and the API only makes sense with this interpretation: The function takes panel ranges as argument and returns ranges. If it doesn't back-transform, what else should it do? Also, it is written in this way for
To make the meaning of the function more explicit, I have renamed it from
Reprex with fixed examples follows below. These geoms don't work at all yet with
library(ggplot2) library(scales) library(tibble) # original example from #2149 df <- data.frame(x=1:6, y=10^(1:6)) ggplot(df, aes(x, y)) + geom_point() + geom_vline(xintercept=3, color='red') + coord_trans(y='log10')
# original example from #2812 mydf <- data.frame(x = 0L:20, y = -10:10) ggplot(data = mydf, aes(x, y)) + geom_point() + coord_trans(x = "log1p") + geom_hline(yintercept = c(-10, 10))
# original example from #2340 log_modulus_trans <- function() trans_new(name = "log_modulus", transform = function(x) sign(x) * log(abs(x) + 1), inverse = function(x) sign(x) * ( exp(abs(x)) - 1 )) set.seed(1) d <- data_frame( tt = rep(1:10, 3), cc = rep(LETTERS[1:3], each = 10), xx = c(rnorm(10, mean = 100, sd = 10), rnorm(10, mean = 0, sd = 10), rnorm(10, mean = -100, sd = 10))) ggplot(data = d, mapping = aes(x = tt, y = xx, group = cc)) + geom_line() + geom_vline(xintercept = 5) + coord_trans(y = "log_modulus")
# examples with geom_line(), from #2149 df <- data.frame(x = c(-Inf, Inf), y = c(1, 2)) p <- ggplot(df, aes(x, y)) + geom_line() + xlim(1, 2) p + coord_polar()
p + coord_trans(y = "log10")
p + coord_trans(x = "log10")
Created on 2018-08-10 by the reprex package (v0.2.0).
hadley left a comment
I think changing the name is probably ok; we'll just need to remember to call out in the NEWS for the next release (since it's a breaking change for extension authors) (but I don't think there are many custom coords in the wild)
Can you please also add some text to the
Is it possible to get this in the bug-fix release? The API change from #2832 causes a problem with plot interaction in Shiny, and this PR would fix it. We'd prefer not to add in a workaround for a single version of ggplot2 that has a different API.
(@schloerke Please feel free to correct me if I've gotten details wrong.)
@wch @schloerke Could you file a separate ggplot2 issue explaining exactly what the problem is? I looked at rstudio/shiny#2184 and it's not immediately clear to me why this PR would fix the problem. More fundamentally, I'm concerned that there's a problem with the current ggplot2 that would be resolved with this PR. It suggests to me we haven't fully thought this through.
@hadley Could you review this once more? I think this is now as much as possible a non-breaking commit:
With these changes, I think it is better to merge this before 3.0.1 than not, since it fixes #2895.
I have also provided documentation for the