ggplot中的年度超出概率标度

时间:2018-11-16 15:45:03

标签: r ggplot2 probability

我有一个数据帧df,该数据帧计算出每日最大液体降水量(AEP)的年度超标概率(P):

df <- tibble::tribble(
   ~AEP,          ~P,
  0.001, 299.0973209,
   0.01, 254.7226534,
   0.03, 233.0298722,
   0.05, 223.9571177,
    0.1, 211.2898816,
    0.3, 190.5075232,
    0.5, 182.3294549,
      1, 170.5569051,
      3, 148.9113334,
      5,  138.991102,
     10, 125.4449161,
     20, 110.1408306,
     25,   104.74124,
     30, 100.2363357,
     40, 92.15268627,
     50, 85.75477796,
     60, 79.55311702,
     70, 73.44249835,
     75, 70.21061223,
     80, 66.79821521,
     90, 58.54507042,
     95, 52.44861458,
     97, 48.86357489,
     99, 43.12184627,
   99.5, 39.72675936,
   99.7,  37.5826596,
   99.9, 33.91759317
  )

我需要做的是创建一个特定的音阶,使中间的中断之间的距离相等,并在两端的两端增加。本书中的一个完美例子在这里:

enter image description here

我自己创建的所有内容(基于此gist的代码块)给我带来了混乱的标签:

library(dplyr)
library(scales)
library(ggplot2)

df %>% 
  ggplot(aes(x = AEP, y = P)) + 
  geom_point() +
  geom_line() +
  scale_y_continuous(name = "Precipitation (P), mm",
                     labels = scales::comma,
                     breaks = seq(0, 300, 50)) +
  scale_x_continuous(name = "AEP, %",
                     breaks = df$AEP,
                     labels = str_c(df$AEP,'%'),
                     expand = c(0.001,0.001)) +
  theme_grey(base_size = 12)

enter image description here

1 个答案:

答案 0 :(得分:0)

我在堆栈溢出的questions中找到了一个答案。 要创建所需的比例,我们需要将qnorm分位数函数应用于所有AEP值(或其他x值),例如

df %>% 
  ggplot(aes(x = qnorm(AEP/100), # transform to quantiles
             y = P)) + 
  geom_point() +
  geom_line() +
  scale_y_continuous(name = "Precipitation (P), mm",
                     labels = scales::comma,
                     breaks = seq(0, 300, 50)) +
  scale_x_continuous(name = "AEP, %",
                     breaks = qnorm(df$AEP/100), #transform
                     labels = df$AEP,
                     expand = c(0.035,0.035)) +
  theme_bw(base_size = 12)

enter image description here