# Adding labels to points using mds and scatter3d package with R

I have a dataset forwhich i have performed an mds and visualized the results using scatterplot3d library. However i would like to see the names of the points on the 3d plot. How do i accomplish that? Each column belongs to a certain group i would like to see which points belong to which groups on the 3dplot.

#generate a distance matrix of the data
d <- dist(data)

#perform the MDS on  3 dimensions and include a Goodness-of-fit (GOF)

fit.mds <- cmdscale(d,eig=TRUE, k=3) # k is the number of dimensions; 3 in this case

#Assign names x,y,z to the result vectors (dimension numbers)
x <- fit.mds$points[,1] y <- fit.mds$points[,2]
z <- fit.mds$points[,3] plot3d <- scatterplot3d(x,y,z,highlight.3d=TRUE,xlab="",ylab="",pch=16,main="Multidimensional Scaling 3-D Plot",col.axis="blue")  • You may also check out rgl. – user88 Sep 1 '10 at 7:35 ## 1 Answer Basically, what you need is to store your scatterplot3d in a variable and reuse it like this: x <- replicate(10,rnorm(100)) x.mds <- cmdscale(dist(x), eig=TRUE, k=3) s3d <- scatterplot3d(x.mds$points[,1:3])
text(s3d$xyz.convert(0,0,0), labels="Origin")  Replace the coordinates and text by whatever you want to draw. You can also use a color vector to highlight the groups of interest. The R.basic package, from Henrik Bengtsson, seems to provide additional facilities to customize 3D plots, but I never tried it. • thanks for this. I would like to higlight the groups using color such that all points from the same group have the same color. Can quite figure out what the convert command does, let me check the documentation though a layman explanation can also help. Thanks a lot! Sep 1 '10 at 6:37 • s3d <- scatterplot3d(x.mds$points[,1:3], color=as.numeric(gl(2,50))) would highlight the first 50 points in black, the remaining ones in red; you can pass any logical vector or factor to suit your data. HTH
– chl
Sep 1 '10 at 11:12