How to create a 3d plot using two separate datasets? in R

533 views Asked by At

I have two separate datasets that I would like to plot in both a scatterplot3d and a plot3d in r How can I do that? I can make the two plots for the datasets individually with just the following:


H <-as.numeric(Dataset$Height)

D <- Dataset$Dose

W <- Dataset$Weight

scatterplot3d(x= W,y= H, z = D, 
              main="Title")
plot3d(x= W,y= H, z = D, col="red", size=7 )

How can I combine the two datasets into one scatterplot3d and one plot3d? The new plots would have the same axises as the ones above. I have attached a picture to hopefully help understand the structure of the datasets

enter image description here

the dput looks like this:

1

There are 1 answers

12
Waldi On BEST ANSWER

You could add a color column to each dataset and rbindthem :

library(scatterplot3d)


m1 <- head(mtcars,10)
m1$color <- 1

m2 <- tail(mtcars,10)
m2$color <- 2 

m <- rbind(m1,m2)

W <- m$cyl
H <- m$mpg
D <- m$disp
C <- m$color

scatterplot3d(x = W, y = H, z = D, 
              main = "Title", color = C)

enter image description here