R for Spatial Statistics


3D Plots

There are a large number of libraries/packages for creating 3D plots in R. Unfortunately, I have found issues with all the ones I have investigated. If you find a good one, please let me know.

Simple Plots

The "rgl" package will allow you to create 3D plots that you can "spin" to view data.

plot3d(mtcars$mpg,mtcars$wt,mtcars$disp, col="red", size=3)

Here is another very cool example from Jochen Voss.


x = seq(-10, 10, length=20)
y = seq(-10, 10, length=20)
z = outer(x,y, function(x,y) dnorm(x, 2, 3)*dnorm(y, 3, 7))

palette = colorRampPalette(c("blue", "green", "yellow", "red")) 
col.table = palette(256)
col.ind = cut(z, 256)
persp3d(x, y, z, col=col.table[col.ind])

Other Packages

Plotly.js is a package that indiciate they allow you to create 2D and 3D plots quicky in R and then export them to the web. However, installing their libraries crashed R for me repeatedly. Also, their JavaScript code is written in a very unprofessional way (almost no documentation and very hard to interpret). For these reasons, I do not use Plotly.

Other Resources

Quick-R Plotting Page

A complete guide to 3D visualization device system in R - R software and data visualization - this is a solid tutorial on how to create rgl plots. Unforutnately, it may be a bit dated.

rgl Overview - another rgl tutorial.