3D scatter plot in R

3D scatter plot

Just need x, y and z in that order.


	plot3d(latitude, longitude, altitude, col="red", size=1)

On a mac, an XQuartz window will open up with the plot.

3D density / contour map

And a density/contour plot. The data here is 2004 Tompkins scores for all the colleges at Cambridge against 2013 scores. As you can see, this graph isn’t that useful for looking at x vs. y.

# Get the data
require(RCurl)  # this is due to an issue with https, R and github
data <- getURL("https://gist.githubusercontent.com/epijim/8819934/raw/6c76df80eb095065a9ce0fa4b8f94410ad528fed/college_data.csv")
data <- read.csv(text=data,stringsAsFactors=F)

# Required libraries
library(rgl) # plots it
library(MASS) # derives the z axis

# Open graph

# Get the z axis
fit <- data[,c("Tompkin_1997","Tompkin_2013")]
fit <- na.omit(fit)
fit = kde2d(fit$Tompkin_1997,fit$Tompkin_2013)

# Plot it
rgl.surface(fit$x, fit$y,   5000*fit$z)

par3d(zoom = 0.5)

# Animate it
M = par3d("userMatrix")
play3d(par3dinterp(userMatrix = list(M, rotate3d(M, pi/2, 1, 0, 0),
                                     rotate3d(M, pi/2, 0, 1, 0))), duration = 5)
A post about: , , , , , and

You May Also Enjoy