0

I want to recreate this plot using ggplot2:

enter image description here

However, I'm struggling to recreate the evenly spaced axis ticks. Here's a simplified code example of what I've got so far:

library(ggplot2)
library(scales)

sim_df <- data.frame(fpr = seq(0.001, 0.999, 0.001),
                     fnr = rev(seq(0.001, 0.999, 0.001)))

ggplot(sim_df, aes(x = fpr, y = fnr)) +
  geom_line() +
  scale_y_continuous(labels = percent_format(1),
                     breaks = c(0.01, 0.05, 0.2, 0.5, 0.8, 0.95, 0.99)) +
  scale_x_continuous(labels = percent_format(1),
                     breaks = c(0.01, 0.05, 0.2, 0.5, 0.8, 0.95, 0.99)) +
  coord_cartesian(xlim = c(0.01, 1), ylim = c(0.01, 1)) 

Created on 2021-08-26 by the reprex package (v2.0.0)

Thank you very much!

Tee
  • 113
  • 1
  • 6
  • I'm not sure on what kind of scale your example is, but it's not a linear one. Closest I could find is the `trans = "asn"` transformation, but it doesn't quite look the same as the example. – teunbrand Aug 26 '21 at 10:53
  • Does this answer your question? [GGplot custom scale transformation with custom ticks](https://stackoverflow.com/questions/38333603/ggplot-custom-scale-transformation-with-custom-ticks) – mnist Aug 26 '21 at 11:43

1 Answers1

1

Here's a solution for anyone wondering. Thanks mnist for the comment.

library(ggplot2)
library(scales)

sim_df <- data.frame(fpr = seq(0.01, 0.99, 0.001),
                     fnr = rev(seq(0.01, 0.99, 0.001)))

ppf_trans <- trans_new(
  "ppf",
  "qnorm",
  "pnorm"
)

ggplot(sim_df, aes(x = fpr, y = fnr)) +
  geom_line() +
  scale_y_continuous(
    trans = ppf_trans,
    labels = percent_format(1),
    limits = c(0.01, 0.99),
    breaks = c(0.01, 0.05, 0.2, 0.5, 0.8, 0.95, 0.99)
  ) +
  scale_x_continuous(
    trans = ppf_trans,
    labels = percent_format(1),
    limits = c(0.01, 0.99),
    breaks = c(0.01, 0.05, 0.2, 0.5, 0.8, 0.95, 0.99))

Created on 2021-08-26 by the reprex package (v2.0.0)

Tee
  • 113
  • 1
  • 6