I have a 3d scatterplot produced 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"))
This works fine. 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 - it just overwrites the old plot. Is there a way to overlay the new plot ?
Although I haven't tested it, I think you should start by trying points3d
instead of plot3d
... and FYI par(new=FALSE)
doesn't have any effect on rgl
plots at all, only base plots.
A very simple solution is to use the add = TRUE
argument:
plot3d(X[want], Y[want], Z[want], col = 'black', add = TRUE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With