问题描述
我有几个累积经验密度函数,我想将它们叠加在一起,以说明两条曲线的差异.正如在上一个问题中指出的那样,绘制ECDF的函数只是plot(Ecdf())
当我阅读精美的手册页时,我确定我可以使用以下内容在彼此之上绘制多个 ECDF:
I have a couple of cumulative empirical density functions which I would like to plot on top of each other in order to illustrate differences in the two curves. As was pointed out in a previous question, the function to draw the ECDF is simply plot(Ecdf())
And as I read the fine manual page, I determined that I can plot multiple ECDFs on top of each other using something like the following:
require( Hmisc )
set.seed(3)
g <- c(rep(1, 20), rep(2, 20))
Ecdf(c( rnorm(20), rnorm(20)), group=g)
但是,我的曲线有时会有些重叠,很难分辨哪个是哪个,就像上面生成此图的示例一样:
However my curves sometimes overlap a bit and can be hard to tell which is which, just like the example above which produces this graph:
我真的很想让这两个 CDF 的颜色不同.但是,我不知道该怎么做.有什么提示吗?
I would really like to make the color of these two CDFs different. I can't figure out how to do that, however. Any tips?
推荐答案
如果没记错的话,我过去曾这样做过.我记得,你需要欺骗它,因为 Ecdf()
是如此糟糕的参数化.我认为在 help(ecdf)
中它暗示它只是一个阶跃函数图,所以你可以估计两个或多个 ecdfs,绘制一个然后通过 lines()
注释.
If memory serves, I have done this in the past. As I recall, you needed to trick it as Ecdf()
is so darn paramterised. I think in help(ecdf)
it hints that it is just a plot of stepfunctions, so you could estimate two or more ecdfs, plot one and then annotate via lines()
.
编辑结果证明它和
Edit Turns out it is as easy as
R> Ecdf(c(rnorm(20), rnorm(20)), group=g, col=c('blue', 'orange'))
因为帮助页面清楚地说明了 col=
参数.但我也发现了一些我明确使用 plot.stepfun()
的脚本.
as the help page clearly states the col=
argument. But I have also found some scriptlets where I used plot.stepfun()
explicitly.
这篇关于R:将一个 ECDF 绘制在另一个不同颜色的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!