Reputation: 704
I am trying to plot different groups (e.g. A, B, C) of data in a 3-D plot where each group has a different colour (e.g. 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?
Upvotes: 0
Views: 3568
Reputation: 13310
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))
Upvotes: 2