[R-sig-Geo] Using the Z value for 3-D polygons?
Torleif Markussen Lunde
torleif.lunde at cih.uib.no
Tue Mar 3 16:58:08 CET 2009
Not exactly what you are looking for, but at least an attempt. Guess you could
also look at the rgl package (never worked for me on Fedora) or misc3d.
Modifying the functions could give you what you want.
require(maptools)
nc <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
proj4string=CRS("+proj=longlat +datum=NAD27"))
for (i in 1:length(nc at data$NWBIR79)) {
zv <- rep(nc at data$NWBIR79[i], length(nc at polygons[[i]]@Polygons[[1]]@coords))
xy <- nc at polygons[[i]]@Polygons[[1]]@coords
colnames(xy) <- c("x", "y")
xyz.tmp <- cbind(xy, zv)
if (i == 1) xyz <- xyz.tmp else xyz <- rbind(xyz, xyz.tmp)
}
#install.packages(c("R.basic"), contriburl="http://www.braju.com/R/repos/")
require(R.basic)
xyz <- data.frame(xyz)
with(xyz, plot3d(x, y, zv, type="n", theta=35, phi=30))
un <- unique(xyz$zv)
my.colors <- colorRampPalette(c("green", "blue", "red"))
mypalette <- my.colors(100)
for (i in 1:length(un)) {
with(xyz, polygon3d(x[zv==un[i]],y[zv==un[i]],zv[zv==un[i]],
col=mypalette[i]))
}
Good luck
Torleif
On Tuesday 03 March 2009 03:29:46 am Jim Burke wrote:
> Hi Everyone,
>
> QUESTION: How can I plot a spatial polygon (SpatialPolygonsDataFrame) as
> 3-d? Perhaps using "spplot.polygons" with its z value?
>
> GOAL: To have a series of polygons look like approximately like the last
> example in the PDF below.
> http://ocw.mit.edu/NR/rdonlyres/Urban-Studies-and-Planning/11-521Spatial-Da
>tabase-Management-and-Advanced-Geographic-Information-SystemsSpring2003/ACA8
>0C9F-4089-403E-9669-50763381D08A/0/lect13c.pdf
>
> EXAMPLE SUGGESTION: Use "spplot.pologons" with the venerable SourceForge
> NC fig21.R example and using its color coding values as the polygon $z
> value? Assuming lat and long are in the sp.
> http://r-spatial.sourceforge.net/gallery/#fig21.R
>
> Then if its not as straightforward as above, what would be the steps to
> convert a spatial polygon to points or something to graph that way?
>
> Thanks,
> Jim Burke
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list