I would like to make a custom CDF where I can view the top part of the CDF with even spacing between 0.9, 0.99, 0.999, etc.
To do this, I tried the following code:
library(ggplot2)
library(scales)
log_tail_trans = function() trans_new("log_tail", function(x) -log10(1-x), function(y) 1 - 10^(-y), breaks=c(0.9, 0.99, 0.999))
p <- ggplot(df, aes(value)) +
stat_ecdf(geom='step') +
coord_trans(y = 'log_tail') +
theme_bw() +
ylim(c(0.68, 0.999999)) +
xlim(c(0, 1000))
This appears to produce the CDF I want, but even though I've specified breaks, I get the default breaks, as seen below:
There's a previous SO question where someone has the same issue without a CDF and the accepted answer is to use scale_y_continuous to modify the breaks after applying coord_trans, but if do the same thing with a CDF, there's no change and I get the plot above.
p <- ggplot(df, aes(value)) +
stat_ecdf(geom='step') +
coord_trans(y = 'log_tail') +
scale_y_continuous(breaks=c(0.9, 0.99, 0.999), labels=c(0.9, 0.99, 0.999)) +
theme_bw() +
ylim(c(0.68, 0.999999)) +
xlim(c(0, 1000))
I've also tried passing my transformation into scale_y_continuous, but if I do that with a CDF, then no transformation occurs and I still get the default breaks even though I'm specifying breaks and labels.
One way I could solve this problem is to "manually" compute the CDF and do the transform myself and then set custom labels, but is there something I'm doing wrong in the above that I need to change or is there an alternate method I can use that takes advantage of ggplot (or tidyverse or other pre-existing) functionality?
This is with R 4.0.3, ggplot 3.3.3, and scales 1.1.1.
question from:
https://stackoverflow.com/questions/65951284/ggplot-stat-ecdf-with-coord-trans-and-custom-ticks