A student is trying to cluster some data. Tree-building things seem to be pretty hopeless (we've tried most of the ones in R, I think). Multi-dimensional scaling produces somewhat tantalising results: things do clump together somewhat, but the clusters overlap a lot. I was wondering if these was an artefact of squeezing it down to 2D, and whether 3D might be better. So loc <- cmdscale(dist(scale(log(data))), k=3) plot(loc) _but_ I still get a 2D plot. I know about persp(), and a bunch of other things in R that give me a 3d view of a 2d field (plots of a function of 2 arguments, in other words). But I want to plot a bunch of 3D points and label them. If the worst comes to the worst, I'll dump them out in a file and use XLispStat to view them. I've asked previously whether there's a spinning plot in R, and have been told that there isn't and why. I've been given one anyway, but it calls Tcl/Tk, and for some reason that doesn't work in my setup.
Richard A. O'Keefe wrote:> A student is trying to cluster some data. Tree-building things seem to > be pretty hopeless (we've tried most of the ones in R, I think). > Multi-dimensional scaling produces somewhat tantalising results: > things do clump together somewhat, but the clusters overlap a lot. > I was wondering if these was an artefact of squeezing it down to 2D, > and whether 3D might be better. So > loc <- cmdscale(dist(scale(log(data))), k=3) > plot(loc) > _but_ I still get a 2D plot. > > I know about persp(), and a bunch of other things in R that give me > a 3d view of a 2d field (plots of a function of 2 arguments, in other > words). But I want to plot a bunch of 3D points and label them.Try cloud() in package lattice or scatterplot3d() in package scatterplot3d.> If the worst comes to the worst, I'll dump them out in a file and use > XLispStat to view them. > > I've asked previously whether there's a spinning plot in R, and have been > told that there isn't and why. I've been given one anyway, but it calls > Tcl/Tk, and for some reason that doesn't work in my setup.There are the packages "rgl" and "djmrgl" (the latter on Windows only) for spinning. Uwe Ligges
I can reccommend ggobi. http://www.ggobi.org/ Install the binary standalone, and the Rggobi package for R (both are from the above site). Works fine for me on Windows 2000, R 1.7.1. Cheers, Simon. Simon Blomberg, PhD Depression & Anxiety Consumer Research Unit Centre for Mental Health Research Australian National University http://www.anu.edu.au/cmhr/ Simon.Blomberg at anu.edu.au +61 (2) 6125 3379> -----Original Message----- > From: Richard A. O'Keefe [mailto:ok at cs.otago.ac.nz] > Sent: Friday, 19 September 2003 3:41 PM > To: r-help at stat.math.ethz.ch > Subject: [R] 3D plotting in R > > > A student is trying to cluster some data. Tree-building > things seem to > be pretty hopeless (we've tried most of the ones in R, I think). > Multi-dimensional scaling produces somewhat tantalising results: > things do clump together somewhat, but the clusters overlap a lot. > I was wondering if these was an artefact of squeezing it down to 2D, > and whether 3D might be better. So > loc <- cmdscale(dist(scale(log(data))), k=3) > plot(loc) > _but_ I still get a 2D plot. > > I know about persp(), and a bunch of other things in R that give me > a 3d view of a 2d field (plots of a function of 2 arguments, in other > words). But I want to plot a bunch of 3D points and label them. > > If the worst comes to the worst, I'll dump them out in a file and use > XLispStat to view them. > > I've asked previously whether there's a spinning plot in R, > and have been > told that there isn't and why. I've been given one anyway, > but it calls > Tcl/Tk, and for some reason that doesn't work in my setup. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
For plotting 3D points, you might want to check the function 'cloud' in the 'lattice' package (some good examples in the help file), you can feed the 3 most important factors to the function and see a 3d rep of your data. A perhaps, a better 3D representation comes from the function 'sm.density' in the 'sm' package, follow the examples for the 3d case in help(sm.density). If the data aggregates itself visually in obvious clusters, you can use the functions 'pam' (for small datasets) or 'clara' (for larger ones) in the package 'cluster' to identify which elements belong to each cluster. In this case you should first determine visually, how many cluster are present, and them, feed this value into these functions, say clara('data', k = 4) where 'data' would, for example, be a 3 columns matrix representing some sort of Principal Component Analysis, etc. and 4 is the number of groups you suspect are present in your data. Alternatevely, you can try independent component analysis on your data. I think is more powerful analysis that goes beyond the classic principal components stuff. Check package 'fastICA' in CRAN for details. Hope this is useful.
On Fri, 19 Sep 2003, Richard A. O'Keefe wrote:> I know about persp(), and a bunch of other things in R that give me > a 3d view of a 2d field (plots of a function of 2 arguments, in other > words). But I want to plot a bunch of 3D points and label them. >I would try {g,x}gobi. -thomas