Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a second 3dplot

Tags:

r

rgl

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 ?

like image 313
LeelaSella Avatar asked Jan 16 '23 02:01

LeelaSella


2 Answers

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.

like image 72
Ben Bolker Avatar answered Jan 28 '23 13:01

Ben Bolker


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

plot3d(X[want], Y[want], Z[want], col = 'black', add = TRUE)
like image 45
Lars Lau Raket Avatar answered Jan 28 '23 12:01

Lars Lau Raket