Skip to content
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

Bug in ggplot2 3.4.0 using scales::probability_trans #5112

Closed
andrewgustar opened this issue Dec 19, 2022 · 2 comments · Fixed by #5115
Closed

Bug in ggplot2 3.4.0 using scales::probability_trans #5112

andrewgustar opened this issue Dec 19, 2022 · 2 comments · Fixed by #5115
Labels
bug an unexpected problem or unintended behavior

Comments

@andrewgustar
Copy link

andrewgustar commented Dec 19, 2022

Prompted by this question on StackOverflow, https://stackoverflow.com/questions/74809918/y-axis-scaling-to-normal-distribution there seems to be a bug in how ggplot2 3.4.0 does axis transformations. The example that works as expected in version 3.3.5, producing a nice straight line, is

data.frame(v = rnorm(1000)) %>% 
    ggplot(aes(x = v)) + 
    stat_ecdf() + 
    scale_y_continuous(trans=scales::probability_trans("norm"))

Compare that to the same code in 3.4.0, which gives an S-shaped curve and also has the y axis starting at 0.5.

In this case, the transformation seems to be using pnorm and qnorm the wrong way round in adjusting the scale and the axis.

I tried a few other transformations, and several of them look odd, so I think this is an example of something deeper in the axis transformation routine.

I'm using R 4.2.2 on Windows 11.

@teunbrand
Copy link
Collaborator

Hi there, thanks for the report. On a first glance, this issue seems the same as #5113.

I think this might be related to the recent change introduced in #4194. Briefly, the default aesthetic for the eCDF stat is y = after_stat(y), and the y column gets back-transformed. Effectively, the system thinks the values that roll out of the stat are already in transformed space, whereas they're not.

It should be relatively easy to fix by giving the computed variable a different name than y.

@andrewgustar
Copy link
Author

Thanks for the reply. I agree it is probably the same as #5113. I haven't found similar problems with other stats, so your explanation sounds promising. Hopefully a simple fix!

@teunbrand teunbrand added the bug an unexpected problem or unintended behavior label Dec 23, 2022
@teunbrand teunbrand modified the milestone: ggplot2 3.4.1 Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants