R:用不同的颜色将一个 ECDF 绘制在另一个 ECDF 之上
我有几个累积经验密度函数,我想将它们绘制在彼此之上,以说明两条曲线的差异。正如在上一个问题中指出的,绘制 ECDF 的函数只是 plot (Ecdf())
当我阅读精美的手册页时,我确定可以使用如下所示的方法在彼此之上绘制多个 ECDF:
require( Hmisc )
set.seed(3)
g <- c(rep(1, 20), rep(2, 20))
Ecdf(c( rnorm(20), rnorm(20)), group=g)
然而,我的曲线有时会重叠一点,很难分辨哪个是哪个,就像上面的例子生成此图:
我真的很想让这两个 CDF 的颜色不同。但是,我不知道该怎么做。有什么建议吗?
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:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果没记错的话,我以前也这么做过。我记得,您需要欺骗它,因为
Ecdf()
的参数化程度太高了。我认为在help(ecdf)
中它暗示它只是一个步进函数图,因此您可以估计两个或多个 ecdf,绘制一个,然后通过lines()
进行注释。编辑事实证明,这就像
帮助页面清楚地说明
col=
参数一样简单。但我也发现了一些我明确使用了plot.stepfun()
的 scriptlet。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 inhelp(ecdf)
it hints that it is just a plot of stepfunctions, so you could estimate two or more ecdfs, plot one and then annotate vialines()
.Edit Turns out it is as easy as
as the help page clearly states the
col=
argument. But I have also found some scriptlets where I usedplot.stepfun()
explicitly.您可以一次添加每条曲线(每条曲线都有自己的样式),例如
You can add each curve one at a time (each with its own style), e.g.
不使用
Ecdf
(看起来Hmisc
不可用):Without using
Ecdf
(doesn't look likeHmisc
is available):