根据条件叠加对图
**编辑:**很抱歉,但情况可能比我所展示的要复杂一些。但是,您的两个脚本都可以工作,尽管由于点重叠,第一个脚本对于大型数据集可能不太清楚!非常感谢萨莎!
我想首先显示几个变量对,然后叠加同一数据集的选定数据。通常,可以使用 par(new=T)
来实现叠加,如下所示:
h<-rnorm(nc) # this variable was used for conditioning
x<-rnorm(nc)
y<-rnorm(nc)
z<-rnorm(nc)
m<-cbind(x,y,z)
pairs(m)
par(new=T)
pairs(m[h>0.7,],col="red")
但是,似乎 par()
设置不适用于这种用法。
那么,格子库可能会有所帮助,例如。 splom()
,但我不知道它是否真的有效,以及如何工作。有人可以提供一些建议吗?
**Edit:**I am sorry, but the situation could be a little bit more complex than I have shown. However, both of your scripts work, although the first might be not so clear for large dataset due to point overlap! Thanks very much Sacha!
I would like to first show the pairs of several variables, and then superimpose the selected data of the same dataset. Usually, the superimpose can be achived using par(new=T)
like this:
h<-rnorm(nc) # this variable was used for conditioning
x<-rnorm(nc)
y<-rnorm(nc)
z<-rnorm(nc)
m<-cbind(x,y,z)
pairs(m)
par(new=T)
pairs(m[h>0.7,],col="red")
However, it seems that the par()
setting does not work for such usage.
Then, probably lattice library could help, ex. splom()
, but I do not know if it really works, and how. Could someone give some suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设
paris
一定是pairs
?pairs
函数没有add
参数,所以它可能也不是那么简单,因为该图有 9 个面板(只需做points 将在最后一个面板中绘制)。但使用
col
在单个图中完成您想要的操作并不难:编辑:
您可以在
pairs
中做的另一件事实际上是在每个面板中设置您想要执行的功能。默认情况下,这是点,但您可以扩展它以包含一些条件:这给出了与之前相同的图片(不同的点,因为我没有设置种子)。简单地制作颜色矢量会更容易实现这一点,但您可以将面板功能设置为您想要的大小。
此外,
...
允许将其他参数传递给points
函数:I assume
paris
must bepairs
? Thepairs
function doesn't have anadd
argument or so, it would probably also not be that trivial since the plot has 9 panels (simply doingpoints
will plot in the last panel). but it is not that hard to do what you want in a single plot usingcol
:Edit:
Another thing you can do in
pairs
is actually set the function you want to do in each panel. By default this ispoints
, but you can extend that to include some conditions:This gives the same picture as before (well different points because I didnt set a seed). Simply making the color vector would be easier to accomplish this, but you can make the panel function as big as you would like.
Also, the
...
allow other arguments to be passed to thepoints
function:lattice::splom
工作正常。颜色索引需要增加 1,因为 R 索引是从 1 开始而不是从 0 开始,并且逻辑向量被强制为 0 和 1。lattice::splom
works fine. The color indexing needs to be boosted by 1 since R indexing is 1 based rather than zero-based and the logical vectors get coerced as 0 and 1.