Adding a second 3dplot

I have a three-dimensional scatter chart created as follows:

library(rgl) N <- 10000 X <- rnorm(N,0,1) Y <- rnorm(N,0,1) Z <- X * Y want <- Z >0 & X>0 palette <- colorRampPalette(c("blue", "green", "yellow", "red")) col.table <- palette(256) col.index <- cut(Z, 256) plot3d(X,Y,Z, col=col.table[col.index]) grid3d(c("x", "y", "z")) 

It works great. Now I want to overlay another plot, so I tried this:

 par(new=F) plot3d(X[want],Y[want],Z[want], col="black") 

However, this fails - he simply rewrites the old plot. Is there a way to overlay a new plot?

+4
source share
3 answers

A very simple solution is to use the add = TRUE argument:

 plot3d(X[want], Y[want], Z[want], col = 'black', add = TRUE) 
+4
source

Although I have not tested it, I think you should start by using points3d instead of plot3d ... and FYI par(new=FALSE) does not affect rgl graphs at all, only the base plots.

+3
source

Another package is used, but with the scatterplot3d package you can add points using the point3d attribute:

 library(scatterplot3d) # main scatterplot s3d<-scatterplot3d(x1,y1,z1,color="black", type="l",box=FALSE,highlight.3d=F, xlab="x",ylab="y",zlab="z") # add some points s3d$points3d(x2,y2,z2,col="red",pch=20) # add a line s3d$points3d(x3,y3,z3,col="blue",type='l') 
+1
source

Source: https://habr.com/ru/post/1444654/


All Articles