【问题标题】:Plot Percentile Indication in R / GGPLOT2在 R / GGPLOT2 中绘制百分比指示
【发布时间】:2012-07-14 09:41:39
【问题描述】:

我有一个两列数据框的基本图(x = "Periods" 和 y = "Range")。

library (ggplot2)
qplot (Periods, Range, data=twocoltest, color=Periods, size = 3,) + geom_jitter(position=position_jitter(width=0.2))

我试图在每个时期添加一条水平线,低于该时期的所有观察值的 90%。 (它不必是水平线,每个周期的任何视觉指示就足够了)。

任何帮助将不胜感激。

【问题讨论】:

  • 我从未使用过ggplot,但这个页面看起来可能会有所帮助:had.co.nz/ggplot2/stat_summary.html。此外,您可以使用quantile(x,probs=0.9) 获得 90% 的百分位数

标签: r ggplot2 line quantile horizontal-line


【解决方案1】:

好的,我已经阅读了 ggplot 帮助,现在开始:

# example data 
twocoltest <- data.frame(Periods=rep(1:3,each=3),Range=1:9)

library(ggplot2)
c <- qplot (Periods, Range, data=twocoltest, color=Periods, size = 3,) + geom_jitter(position=position_jitter(width=0.2))
q90 <- function(x) {quantile(x,probs=0.9)}

c + stat_summary(fun.y=q90, colour="red", geom="crossbar", size = 1, ymin=0, ymax=0) 

【讨论】:

  • 您也可以尝试添加geom = "line" 和aes(group = 1)(并删除ymin 和ymax),这可能会使眼睛更容易一些。
  • @joran - 我迷路了。在什么时候添加aes(group=1)?我现在只是以一条线连接 90%ile 结束。
  • 非常感谢。 thelatemail 的示例可以满足我的需要。
  • 抱歉,我的意思是连接第 90 个 %-ile 的单行可能看起来更好一些,仅此而已。
  • 最后一个问题,我可以成功添加额外的分位数行,例如 qz
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-09
  • 2015-05-26
  • 2020-10-16
  • 1970-01-01
相关资源
最近更新 更多