I would like to create a 3d scatterplot that is interactive in the sense that I can spin it on its axes to better visualize some PCA results I have. What are the options in R? I've looked at RGL and perhaps it will suffice but it wasn't apparent from the documentation I found. Any demo scripts available for a package that will work? Mark -- Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, & Mobile & VoiceMail (317) 663-0513 Home (no voice mail please) ****************************************************************** [[alternative HTML version deleted]]
#Install library rgl
#here is the is the function:
rgl.plot3d<-function(z, x, y, cols="red",axes=T,new=T)
{xr<-range(x)
x01<-(x-xr[1])/(xr[2]-xr[1])
yr<-range(y)
y01<-(y-yr[1])/(yr[2]-yr[1])
zr<-range(z)
z01<-(z-zr[1])/(zr[2]-zr[1])
if(new) rgl.clear()
if(axes)
{xlab<-pretty(x)
ylab<-pretty(y)
zlab<-pretty(z)
xat<-(xlab-xr[1])/(xr[2]-xr[1])
yat<-(ylab-yr[1])/(yr[2]-yr[1])
zat<-(zlab-zr[1])/(zr[2]-zr[1])
rgl.lines(c(0,1.1),0,0)
rgl.lines(0,c(0,1.1),0)
rgl.lines(0,0,c(0,1.1))
rgl.texts(xat,-.05,-.05,xlab)
rgl.texts(-.05,yat,-.05,ylab)
rgl.texts(-.05,-.05,zat,zlab)
rgl.texts(c(0.5,-.15,-.15),c(-.15,.5,-.15),c(-.15,-.15,.5),
c(deparse(substitute(x)),deparse(substitute(y)),deparse(substitute(z))))
}
rgl.spheres(x01,y01,z01,.01,color=cols)
}
#and here is how you call it
library(rgl)
data(iris)
iris.pc<-prcomp(iris[,1:4],scale=T)
rgl.plot3d(iris.pc$x[,1],iris.pc$x[,2],iris.pc$x[,3])
# different colors
rgl.plot3d(iris.pc$x[,1],iris.pc$x[,2],iris.pc$x[,3],col=unclass(iris[,5])+1)
#you could also change the labels and everything else. Enjoy!
Mark W Kimpel wrote:>
> I would like to create a 3d scatterplot that is interactive in the sense
> that I can spin it on its axes to better visualize some PCA results I
> have.
> What are the options in R? I've looked at RGL and perhaps it will
suffice
> but it wasn't apparent from the documentation I found.
>
> Any demo scripts available for a package that will work?
>
> Mark
>
> --
> Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
> Indiana University School of Medicine
>
> 15032 Hunter Court, Westfield, IN 46074
>
> (317) 490-5129 Work, & Mobile & VoiceMail
> (317) 663-0513 Home (no voice mail please)
>
> ******************************************************************
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
View this message in context:
http://www.nabble.com/interactive-rotatable-3d-scatterplot-tp17030023p17030164.html
Sent from the R help mailing list archive at Nabble.com.
Hi Mark, Try using ggobi via Rggobi. ggobi is aimed at higher dimension multivariate data but it does a very useful service in 3-D projections, do a manually controlled tour ... I've used this to tweak PCA results and find fine structure, Richard Mark Kimpel wrote:> I would like to create a 3d scatterplot that is interactive in the sense > that I can spin it on its axes to better visualize some PCA results I have. > What are the options in R? I've looked at RGL and perhaps it will suffice > but it wasn't apparent from the documentation I found. > > Any demo scripts available for a package that will work? > > Mark > >-- Dr Richard Rowe Zoology & Tropical Ecology School of Marine & Tropical Biology James Cook University Townsville 4811 AUSTRALIA ph +61 7 47 81 4851 fax +61 7 47 25 1570 JCU has CRICOS Provider Code 00117J
Duncan, I would be happy to do as you suggest. Assuming I use my current 64-bit OS, how do I achieve this? Won't openGL be 64-bit? What compiler flags do I use to force R to go 32-bit? This is not something I've done before. Attached is a screenshot of what I get with the script that Yasir sent me. Mark On Sat, May 3, 2008 at 7:07 AM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:> On 02/05/2008 10:00 PM, Mark Kimpel wrote: > > > When I do example(plot3d) I get a nice, static 3d plot, which does not > > rotate when I click and mouse over it. Should it be rotatable? If so, is > > there a common reason why it might not be? I am running Ubuntu 8.04 > > (Hardy > > Heron) and my sessionInfo is below. Thanks! Mark > > > > It should be rotatable. By default, the mouse control would be something > like a trackball: you click to grab part of the display, and drag it to > rotate. > > I haven't heard of anyone else with your problems, but I don't know anyone > else using rgl on a 64 bit platform, so there could easily be bugs there. > Can you build a 32 bit version of R and rgl and see if the problem is > there, too? > > Duncan Murdoch > > > > > sessionInfo() > > > > > R version 2.7.0 (2008-04-22) > > x86_64-unknown-linux-gnu > > > > locale: > > > > LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C > > > > attached base packages: > > [1] splines tools stats graphics grDevices datasets utils > > [8] methods base > > > > other attached packages: > > [1] scatterplot3d_0.3-25 rgl_0.77 affycoretools_1.12.0 > > [4] annaffy_1.12.0 gcrma_2.12.0 matchprobes_1.12.0 > > [7] biomaRt_1.14.0 RCurl_0.9-0 GOstats_2.6.0 > > [10] Category_2.6.0 genefilter_1.20.0 survival_2.34-1 > > [13] RBGL_1.16.0 annotate_1.18.0 xtable_1.5-2 > > [16] GO.db_2.2.0 graph_1.18.0 limma_2.14.0 > > [19] RColorBrewer_1.0-2 rat2302_2.2.0 MASS_7.2-41 > > [22] KEGG.db_2.2.0 AnnotationDbi_1.2.0 RSQLite_0.6-8 > > [25] DBI_0.2-4 lme4_0.99875-9 Matrix_0.999375-9 > > [28] lattice_0.17-6 affy_1.18.0 preprocessCore_1.2.0 > > [31] affyio_1.8.0 Biobase_2.0.0 mclust_3.1-3 > > > > loaded via a namespace (and not attached): > > [1] cluster_1.11.10 grid_2.7.0 tcltk_2.7.0 XML_1.94-0 > > > > On Fri, May 2, 2008 at 8:42 PM, Duncan Murdoch <murdoch at stats.uwo.ca> > > wrote: > > > > Mark Kimpel wrote: > > > > > > I would like to create a 3d scatterplot that is interactive in the > > > > sense > > > > that I can spin it on its axes to better visualize some PCA results > > > > I > > > > have. > > > > What are the options in R? I've looked at RGL and perhaps it will > > > > suffice > > > > but it wasn't apparent from the documentation I found. > > > > > > > > Any demo scripts available for a package that will work? > > > > > > > > > > > > example(plot3d) in rgl. > > > > > > Duncan Murdoch > > > > > > Mark > > > > > > > > > > > > > > > > > > > > > > > >-- Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, & Mobile & VoiceMail (317) 663-0513 Home (no voice mail please) ****************************************************************** -------------- next part -------------- A non-text attachment was scrubbed... Name: rgl.screenshot.png Type: image/png Size: 70098 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080503/4c7e528c/attachment.png>
I am facing the same problem than Mark Kimpel with the rgl package : Running various 3D rendering I'm always faced with a static 3d plot, which does not rotate when I click and mouse over it. I'm running Ubuntu linux 7.10 with a 32bit processor, thus the problem is not arising from 64bit issues. Fran?ois.> sessionInfo()R version 2.7.0 (2008-04-22) i486-pc-linux-gnu locale: LC_CTYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=fr_FR.UTF-8;LC_COLLATE=fr_FR.UTF-8;LC_MONETARY=C;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] sp_0.9-17 rgl_0.73 loaded via a namespace (and not attached): [1] grid_2.7.0 lattice_0.17-2 -- Guilhaumon Fran?ois Laboratoire "Ecosyst?mes Lagunaires" UMR 5119 cc 93 Bat 24 Universit? Montpellier II 34 095 Montpellier France http://www.ecolag.univ-montp2.fr Tel : +33 4 67 14 45 71 Fax : +33 4 67 14 37 19