【问题标题】:Evenly spaced ticks in ggplot2ggplot2中均匀间隔的刻度
【发布时间】:2021-08-26 10:07:51
【问题描述】:

我想用 ggplot2 重新创建这个情节:

但是,我正在努力重新创建均匀间隔的轴刻度。这是到目前为止我所拥有的简化代码示例:

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)) 

reprex package (v2.0.0) 于 2021 年 8 月 26 日创建

非常感谢!

【问题讨论】:

标签: r ggplot2


【解决方案1】:

这是任何想知道的人的解决方案。感谢 mnist 的评论。

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))

reprex package (v2.0.0) 于 2021 年 8 月 26 日创建

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 2022-08-03
    相关资源
    最近更新 更多