R:用不同的颜色将一个 ECDF 绘制在另一个 ECDF 之上

发布于 2024-11-15 20:51:50 字数 496 浏览 1 评论 0原文

我有几个累积经验密度函数,我想将它们绘制在彼此之上,以说明两条曲线的差异。正如在上一个问题中指出的,绘制 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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

榆西 2024-11-22 20:51:50

如果没记错的话,我以前也这么做过。我记得,您需要欺骗它,因为 Ecdf() 的参数化程度太高了。我认为在 help(ecdf) 中它暗示它只是一个步进函数图,因此您可以估计两个或多个 ecdf,绘制一个,然后通过 lines() 进行注释。

编辑事实证明,这就像

  R> Ecdf(c(rnorm(20), rnorm(20)), group=g, col=c('blue', 'orange'))

帮助页面清楚地说明 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 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'))

as the help page clearly states the col= argument. But I have also found some scriptlets where I used plot.stepfun() explicitly.

花桑 2024-11-22 20:51:50

您可以一次添加每条曲线(每条曲线都有自己的样式),例如

Ecdf(rnorm(20), lwd = 2)
Ecdf(rnorm(20),add = TRUE, col = 'red', lty = 1)

You can add each curve one at a time (each with its own style), e.g.

Ecdf(rnorm(20), lwd = 2)
Ecdf(rnorm(20),add = TRUE, col = 'red', lty = 1)
不一样的天空 2024-11-22 20:51:50

不使用 Ecdf (看起来 Hmisc 不可用):

set.seed(3)
mat <- cbind(rnorm(20), rnorm(20))
matplot(apply(mat, 2, sort), seq(20)/20, type='s')

Without using Ecdf (doesn't look like Hmisc is available):

set.seed(3)
mat <- cbind(rnorm(20), rnorm(20))
matplot(apply(mat, 2, sort), seq(20)/20, type='s')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文