Tee
Tee

Reputation: 133

Evenly spaced ticks in ggplot2

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!

Upvotes: 0

Views: 930

Answers (1)

Tee
Tee

Reputation: 133

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)

Upvotes: 1

Related Questions