Solved – Adding labels to points using mds and scatter3d package with R

multidimensional scalingr

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")

Best 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.

Related Question