0

I want to create a cumulative frequency plot with probability scaling on the y-axis. When I transform the y-axis from the regular scaling to the probability scaling, the scale is not applied correctly.

plt <- ggplot(df, aes(df[,"test_values"]))
plt = plt + stat_ecdf()
last_plot()
plt = plt + stat_ecdf(geom="point")
last_plot()
last_plot()
plt = plt + ylab("Cumulative Frequency")
last_plot()
plt = plt + scale_x_continuous(labels = scales::scientific,breaks = scales::pretty_breaks(n = 8))
last_plot()

Until this line everything is fine: unscaled y axis

Then I want to scale the y axis

plt = plt + scale_y_continuous(trans=probability_trans("norm"), breaks=c(0.001,0.01,0.05,0.25,0.5,0.75,0.95,0.99,0.999))
last_plot()

And i get this: probability scale y axis

I would expect the value to be from 0 to 1 and not from 0.5 to 0.95.

I have scales version 1.2.1 and ggplot2 3.4.0 with R version 4.2.2

Kenne
  • 11
  • 3
  • If you are not explicitly loading the `scales` package you will need to use the form `trans=scales::probability_trans("norm")`, which works for me. – Andrew Gustar Dec 15 '22 at 10:27
  • I am loading the scales package, but also with `trans=scales::probability_trans("norm")` it gives the same result. – Kenne Dec 15 '22 at 11:47
  • It might be something odd about your data. Does this example work?...`data.frame(test_values = rnorm(1000)) %>% ggplot(aes(x = test_values)) + stat_ecdf(geom="point") + scale_y_continuous(trans=scales::probability_trans("norm"))` – Andrew Gustar Dec 15 '22 at 11:54
  • it does look nearly the same, with y values also scaled from 0.5 to 0.95 – Kenne Dec 15 '22 at 13:43
  • This seems to be a bug in ggplot2 3.4.0 - if you roll back to 3.3.5 it works as expected (I used the `versions` package to roll back) – Andrew Gustar Dec 19 '22 at 18:23
  • I've reported it on the ggplot2 github page. – Andrew Gustar Dec 19 '22 at 18:48

0 Answers0