Building a three-dimensional surface area with an overlay contour map using R

I have a set of 3 tuples (points X, Y, Z) that I want to build using R.

I want to create a surface graph from the data and overlay a contour map on the surface graph to give the impression that the contour map is a “shadow” or projection from a surface area. The outline map should appear below the surface area.

My dataset looks something like this:

Axis | Data Type ------------------- X | Date value Y | Float value Z | Float value 

How can i achieve this?

+57
r statistics plot 3d
Dec 13 '09 at 12:53
source share
1 answer

Edit:

I just saw that you indicated that one of your measurements is a date. In this case, look at the Jeff Ryan chartSeries3d , which is designed for 3D time series charts. Here it shows the yield curve over time:

chartSeries example http://www.quantmod.com/examples/chartSeries3d/chartSeries3d-thumb.png

Original answer:

As I understand it, you want the counting map to be a projection onto a plane under 3D graphics. I do not think that there is an easy way to do this, except for creating two stories, and then combining them. You may find a spatial view useful for this .

There are two main R packages for 3D building: rgl (or you can use the associated misc3d ) and scatterplot3d .

RGL

The rgl package uses OpenGL to create interactive 3D graphics ( read more on the rgl website ). Here is an example using the surface3d function:

 library(rgl) data(volcano) z <- 2 * volcano # Exaggerate the relief x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N) y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W) zlim <- range(z) zlen <- zlim[2] - zlim[1] + 1 colorlut <- terrain.colors(zlen,alpha=0) # height color lookup table col <- colorlut[ z-zlim[1]+1 ] # assign colors to heights for each point open3d() rgl.surface(x, y, z, color=col, alpha=0.75, back="lines") 

The alpha parameter makes this surface partially transparent. Now you have an interactive 3D surface graph and you want to create a counting map below. rgl allows you to add additional graphics to an existing image:

 colorlut <- heat.colors(zlen,alpha=1) # use different colors for the contour map col <- colorlut[ z-zlim[1]+1 ] rgl.surface(x, y, matrix(1, nrow(z), ncol(z)),color=col, back="fill") 

On this surface, I set the heights = 1, so that we have a plane below another surface. It looks like this and can be rotated with the mouse:

3D surface graph http://i45.tinypic.com/12637gy.jpg

scatterplot3d

scatterplot3d is a bit more like other build functions in R ( read vignette ). Here is a simple example:

 temp <- seq(-pi, 0, length = 50) x <- c(rep(1, 50) %*% t(cos(temp))) y <- c(cos(temp) %*% t(sin(temp))) z <- c(sin(temp) %*% t(sin(temp))) scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue", col.grid="lightblue", main="scatterplot3d - 2", pch=20) 

In this case, you will need to overlay the images. R-Wiki has a nice post on creating a tanslucent background image .

+83
Dec 13 '09 at 15:12
source share



All Articles