如何并行向两个图添加点? (在R中)

发布于 2024-12-21 02:56:08 字数 1167 浏览 5 评论 0原文

我正在寻找并行向三个不同绘图添加点的方法。

我在一个窗口中有三个名为 s3d1s3d2s3d3 的散点图

layout(matrix(c(1,2,1,3),2, 2, byrow = TRUE))
s3d1<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
s3d2<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
s3d3<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)

如果我尝试向 s3d1 添加点>,

s3d1$points3d(mtcars[,3],mtcars[,4],mtcars[,5],col="red")

这些点将转到 s3d3,但不会转到 s3d1。我缺少什么?

更多信息:我在运行程序时获取数据点。因此,当我获得特定于该特定图的数据时,我需要向每个图添加点。

更新:

也尝试过 par() 函数

par(fig=c(0,0.65,0,1), new=TRUE)
s3d1<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
par(fig=c(0.7,1,0.5,1), new=TRUE)
s3d2<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
par(fig=c(0,0.65,0,1), new=TRUE)
s3d1$points3d(mtcars[,3],mtcars[,4],mtcars[,5],col="red")

s3d1$points3d 不会向 s3d1 添加新点(并且甚至连 s3d2 都没有)。有什么想法吗?

I am looking for ways to add points to three different plots in parallel.

I have three scatter plots named s3d1, s3d2 and s3d3 in a single window

layout(matrix(c(1,2,1,3),2, 2, byrow = TRUE))
s3d1<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
s3d2<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
s3d3<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)

If I try to add points to s3d1,

s3d1$points3d(mtcars[,3],mtcars[,4],mtcars[,5],col="red")

The points would go to s3d3 but not s3d1. What am I missing ?

More info : I obtain data points while running a program. So, I need to add points to each of these plots as-and-when I get the data specific to that particular plot.

Update :

Tried par() function as well

par(fig=c(0,0.65,0,1), new=TRUE)
s3d1<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
par(fig=c(0.7,1,0.5,1), new=TRUE)
s3d2<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
par(fig=c(0,0.65,0,1), new=TRUE)
s3d1$points3d(mtcars[,3],mtcars[,4],mtcars[,5],col="red")

s3d1$points3d doesn't add new points to s3d1 (and not even to s3d2). Any ideas ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

暖风昔人 2024-12-28 02:56:09

如果您通过尝试执行 s3d1$points3d 来查看 points3d() 的源代码,您会发现它只是将点添加到假设为的现有绘图中已经开放了。换句话说,点/图不存储在 s3d1,2,3 对象中,而仅存储绘制到不同视图所需的转换信息。

Soo,要做你想做的事,你只需要使用普通的图形设备命令。例如,dev.new 将打开一个新的绘图窗口,而 dev.set 可以在活动窗口之间切换。您可以执行以下操作:

dev.new(); h1=dev.cur()
s3d1<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
dev.new(); h2=dev.cur()
s3d2<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
dev.new(); h3=dev.cur()
s3d3<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
dev.set(h1)
s3d1$points3d(mtcars[,3],mtcars[,4],mtcars[,5],col="red")

另请查看 ?dev.new 以获取更多信息。

If you look at the source of points3d() by just trying to execute s3d1$points3d, you'll see that it just adds points to an existing plot that is assumed to be already open. In other words, the points/plot are not stored in the s3d1,2,3 objects, but simply the transformation info needed to plot to the different views.

Soo, to do what you're trying to do, you'll just have to use the normal graphics device commands. For instance, dev.new will open a new plot window, and dev.set can switch between the active ones. You could do something like:

dev.new(); h1=dev.cur()
s3d1<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
dev.new(); h2=dev.cur()
s3d2<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
dev.new(); h3=dev.cur()
s3d3<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
dev.set(h1)
s3d1$points3d(mtcars[,3],mtcars[,4],mtcars[,5],col="red")

Also check out ?dev.new for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文