How do I make 3D sphere data points in scatterplot3d in R?
1
0
Entering edit mode
8.9 years ago
rockquark ▴ 10

Hi All,

I have made a 3D PCA plot using scatterplot3d in R. I want to make the data points look like spheres so it looks like the data has 3D structure. I'm fairly new to R so still learning the best ways to use R. I saw that rgl.spheres command can do this, but I'm having trouble incorporating this in my script to make it work. What is the easiest way to make this happen?

The script I'm currently using that gives me a 3D PCA plot with normal 2D looking data points is:

color=c('black','black','black','blue','blue','blue',
        'red','red','red','green','green','green')

scatterplot3d(data.PC$x[,1:3], pch=19, color=color, cex.symbols=1.5, angle = 40,
                        box = FALSE, type='h')

Any help will be much appreciate!!

Thanks,
Afshin

R • 5.1k views
ADD COMMENT
0
Entering edit mode

I am still confused about why you would do a 3D plot of a PCA, but in any case this has been asked before: R package used for PCA plotting in a paper (rice RNA-Seq)

ADD REPLY
0
Entering edit mode

Mmmhh... Why are you confused? Conceptually plotting 3 components is the same as plotting 2 (or 1). I guess most PCA plots show the first 2 components only because A) 2D plots look good on paper and most of the information is anyway in the 1st and 2nd PC B) 3D plots are usually tricky to visualize on 2D devices.

ADD REPLY
1
Entering edit mode
8.9 years ago

Please see my answer in this thread, which includes a snippet of source for drawing 3D scatterplots in R via rgl: A: R package used for PCA plotting in a paper (rice RNA-Seq)

As noted in comments, viewing a 3D structure on a 2D surface - like a screen or a piece of paper - can be problematic, in that it is not easy to communicate point depth. It can be easy to misinterpret a figure that shows point clusters, which end up being illusions once the plot is seen from a different angle of rotation.

My answer discusses one way to deal with this problem, namely to make a set of figures rotated at, say, 5 or 10 degree increments, stitched into an animation that shows how points actually disperse.

To reduce the amount of work in making GIF animations, I created a web application called Cubemaker that allows more flexible interaction than the static view that rgl offers. This tool was made originally to share interactive views of PCA and PCoA datasets, but it will import any three-dimensional dataset, along with optional metadata.

More information about Cubemaker is available here and here in this slide deck

Cubemaker will let you make color and other metadata changes, reorient the cube, animate its rotation, and share changes and view settings via a persistent web link that can be emailed, posted in a blog, or embedded in a presentation. It is useful for exploring PCA or PCoA results, and if things look genuinely interesting, then more time can be spent on programming rgl to make a publication-quality figure.

ADD COMMENT

Login before adding your answer.

Traffic: 917 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6