[R] 3dscatterplot -different colors for different factors of the same variable

Moreno Ignazio Coco M.I.Coco at sms.ed.ac.uk
Tue May 13 18:49:38 CEST 2008


Dear R users,

I was trying to do a 3d scatterplot for the following set of datas:

         "obj"  "time" "X" "Y"
"1"  "yellow"  "333" "388.7" "492.3"
"2"  "yellow"  "567" "388.7" "492.3"
"3"  "green"   "621" "135.5" "371.7"
"4"  "green"   "1039" "135.5" "371.7"
"5"  "red"     "1373" "744.1" "205.0"
"6"  "red"     "1763" "744.1" "205.0"

The points should be drew in the plot taking information of "time",  
"X" and "Y". The colors of these points should be assigned according  
to the information contained in variable "obj".
What I did but it didn't work out is:

1) Plotting only one set of points (the green one)

s3d<-scatterplot3d(greenpts[,3],greenpts[,2],greenpts[,4],type="p",scale.y=4,  
angle=10, color="green")

and try to overlay the others (as you normally would do with "plot"):

s3d$points3d(redpts[,3],redpts[,2],redpts[,4],col="red",type="o")
s3d$points3d(yellowpts[,3],yellowpts[,2],yellowpts[,4], col="yellow",type="o")
s3d$points3d(bluepts[,3],bluepts[,2],bluepts[,4],col="blue",type="o")
s3d$points3d(pinkpts[,3],pinkpts[,2],pinkpts[,4],col="pink",type="o")

R has plotted only the first set and wasn't able to overlay other points.

2) I have generated a "for" loop that should have taken points  
information ,arranged into a list object, plotting them one by one.
- listpoints = list(X,Y,time)
-color<-rep("black",26) ##solution found in one of the discussion  
around scatterplot
color[mat1$obj=="green"]<-"green"
color[mat1$obj=="yellow"]<-"yellow"
color[mat1$obj=="red"]<-"red"
color[mat1$obj=="pink"]<-"pink"
color[mat1$obj=="blue"]<-"blue"

for (i in 1:26)
points3d(listpoints[i],type=1, col=color[i])

Also this way didn't work out. Do you have any solution?
Many thanks

Moreno

P.S. I have tried also points3d(rgl) trying to follow an explanation  
given in the forum but i haven't understood how to set the function.

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.



More information about the R-help mailing list