[R] plot3d, color points by group

Dieter Menne dieter.menne at menne-biomed.de
Fri Feb 18 19:03:42 CET 2011



Kari-4 wrote:
> 
> 
> I've created a 3d scatterplot, and had no problems labeling the points.
> However, I've been really struggling to change the color of the points
> based
> on a factor (see 'group' below).  Is such a thing possible?
> 
> 

Its always polite to make the example self-running by adding the library and
the input. But your's was close.
Dieter


library(rgl)
ttt = textConnection("
food group      x      y      z
apple  fruit  0.216 -0.112 -0.893
orange fruit  0.814  0.097  0.460
broccoli veg -0.239  0.240 -0.425
banana  fruit  0.222  0.968 -0.050
parsnip  veg  0.139  0.897  0.378
garlic     veg -0.104  0.510 -0.400
")

colors =c("green","blue","red")
pca <-  read.table(ttt,header=TRUE)
p3d<- plot3d(pca$x, pca$y, pca$z, xlab="Component 1", ylab="Component 2",
zlab="Component 3", 
col=as.integer(pca$group) ,
box=FALSE, size=5)
food.v<-as.vector(pca$food)
text3d(pca$x, pca$y, pca$z, food.v, cex=0.9, adj = 1)


-- 
View this message in context: http://r.789695.n4.nabble.com/plot3d-color-points-by-group-tp3312955p3313268.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list