简体   繁体   中英

R Plotting multiple groups of data in a single 3D plot

I am trying to plot different groups (eg A, B, C) of data in a 3-D plot where each group has a different colour (eg red, green, blue) by using scatterplot3d(). Currently, I am in position of creating 3-D plots for each of the data set. However, I cannot find a way to plot all the data in the same 3d plot by using different colours.

I would like to achieve something similar with the 2-D case where you can initially plot the first group by plot() and then add the rest of the groups with points().

Have anyone faced the same issue?

You could use plot3d() from rgl. Since you provided no data, I made some up...

require(MASS)
mus <- 1:3
sigma <- diag(1, 3, 3)
mat <- mvrnorm(100, mus, sigma)

df <- data.frame(rbind(mvrnorm(100, mus, sigma),
            mvrnorm(100, 2*mus, sigma),
            mvrnorm(100, 3*mus, sigma)))

df$fac <- factor(rep(LETTERS[1:3], each = 100))

require(rgl)
plot3d(df$X1, df$X2, df$X3, col=as.numeric(df$fac))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM