-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Possible bug in stage()
/after_stat()
with scale transformations.
#4155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm yet to figure out what's happening, but probably we need to somehow bypass this transformation in the end of Lines 326 to 330 in 3be0acc
Actually, abusing library(ggplot2)
l <- geom_point(aes(x = stage(date, after_stat = x),
y = unemploy))
l$stat$retransform <- FALSE
ggplot(economics) + l Created on 2020-08-14 by the reprex package (v0.3.0) |
Yes, the retransform trick totally works in my case, see example below. Note that the I never noticed the I still have the gut feeling that the library(ggh4x) # https://github.com/teunbrand/ggh4x
#> Loading required package: ggplot2
p <- ggplot(economics, aes(date)) +
stat_rle(
aes(label = date > as.Date("1980-01-01") & date < as.Date("1990-01-01")),
align = "center"
) +
geom_line(aes(y = unemploy))
# Gives error
print(p)
#> Error: Invalid input: date_trans works with objects of class Date only
p$layers[[1]]$stat$retransform <- FALSE
# Output is fine
print(p) Created on 2020-08-14 by the reprex package (v0.3.0) |
Yes, I totally agree with you! Sorry probably my comment was confusing. I meant
I bet there's no downsides. It appears only the following two places: Lines 52 to 56 in 112f960
Lines 328 to 330 in 3aa2937
|
Another example why I think this should be fixed. The library(ggplot2)
d <- data.frame(value = 16)
ggplot(d) +
geom_point(aes(value, 0), colour = "red", size = 10) +
geom_point(aes(stage(value, after_stat = x), 0), colour = "black", size = 10) +
scale_x_sqrt(limits = c(0, 16), breaks = c(0, 4, 16)) |
Ah yes that result indeed doesn't make sense, so the bug applies to non-date transformations too. I should probably generalise the title of the issue for any transformation. As an aside, shouldn't the 0-break/label have been rendered too? |
stage()
/after_stat()
with dates.stage()
/after_stat()
with scale transformations.
Good catch, thanks! I've filed another issue here: #4193 |
Great stuff @yutannihilation, thanks for solving the issue! |
Thank you, too! Your exploration really helped. I'm glad that we solved this at last! |
I think I might have found a bug with either the scales or the
stage()
/after_stat()
functions in combination with dates.I came across this when making a custom stat where I wanted to put
default_aes = aes(xmin = after_stat(start), xmax = after_stat(end))
in the ggproto methods, wherestart
andend
are computed variables.What happens is that when I try to apply a
stage()
orafter_stat()
to a date variable, it gives me an error that the date transformation is invalid. I don't think it is a problem with stats, as it also shows up withstat_identity()
.The attempted plot below is not very interesting, but it is the most minimal example I could come up with.
The error above doesn't happen for integer or numeric data.
And also the error can be rescued by formatting the output as a date again, but this seems overly verbose and seems difficult to anticipate in a custom stat.
The same is true for other geoms and aesthetics as well. Here are similar examples with
after_stat()
instead ofstage()
.Created on 2020-07-31 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: