首页 > 解决方案 > 在 ecdf ggplot2 中添加参考线

问题描述

我正在尝试在 R 中向我的 ecdf 图添加参考线。这是我的数据的样子。

dput(head(pppp))
structure(list(B_code= c(1121058L, 1121058L, 1121058L, 1121058L, 
1121058L, 1121058L), Distance = c(0.9, 1.3, 1.6, 1.9, 2.1, 2.2
), AI_i = c(422.717247745409, 51.1207837179096, 70.5839979587593, 
13.5040949782694, 371.762616959738, 21.395033572169)), row.names = c("107924", 
"107922", "107925", "107910", "107933", "107923"), class = "data.frame")

在此处输入图像描述

我暗示的代码是

   
  pppp<-pppp[c(order(pppp$Distance)),]
  AI = pppp$AI_i                      
  val<-ecdf(AI)
  par(new=T)
  ggplot(test2, aes(AI)) + 
    stat_ecdf(geom = "line") +
    scale_y_continuous(labels = scales::percent) +     
    theme_bw() +
    theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))+
    xlab("Calculated Accessibility Value") +
    ylab("Percent")

我应该使用什么代码将水平和垂直参考线添加到 ecdf 的 0.7% 的 x 和 y 值?我希望第一个 x 值用 y 值 0.7 表示。

我将不胜感激一些建议或帮助。

标签: rggplot2ecdf

解决方案


你可以试试geom_hline()geom_vline()


推荐阅读