【发布时间】:2017-12-22 03:17:34
【问题描述】:
我正在尝试生成仅 ggplot 的 C.D.F.绘制我的一些数据。我还希望能够在顶部绘制任意数量的百分位数。我有一个解决方案可以在我的曲线上添加一个点,但对于多个值会失败。
这适用于绘制一个百分位值
TestDf <- as.data.frame(rnorm(1000))
names(TestDf) <- c("Values")
percentiles <- c(0.5)
ggplot(data = TestDf, aes(x = Values)) +
stat_ecdf() +
geom_point(aes(x = quantile(TestDf$Values, percentiles),
y = percentiles))
然而这失败了
TestDf <- as.data.frame(rnorm(1000))
names(TestDf) <- c("Values")
percentiles <- c(0.25,0.5,0.75)
ggplot(data = TestDf, aes(x = Values)) +
stat_ecdf() +
geom_point(aes(x = quantile(TestDf$Values, percentiles),
y = percentiles))
有错误
错误:美学长度必须为1或与数据相同(1000):x,y
如何向stat_ecdf() 绘图添加任意数量的点?
【问题讨论】:
-
ggplot(data = TestDf, aes(x = Values)) + stat_ecdf() + geom_point(data = data.frame(x=quantile(TestDf$Values, percentiles), y=percentiles), aes(x=x, y=y)) -
嗨@Masoud,这正是我想要的,非常感谢!
标签: r dataframe plot ggplot2 statistics