使用RGL的3D地理图

时间:2013-08-14 08:28:33

标签: r plot geospatial reshape rgl

我是新手重塑和rgl,看看我是否理解正确我正在浏览http://www.r-bloggers.com/creating-3d-geographical-plots-in-r-using-rgl/中提供的代码,它似乎与网站上提供的数据集一起使用,但不适用于我和我不明白为什么,但我得到的只是一个灰色的图像。 这是我的数据集http://www.mediafire.com/download/8ifpssvdyr665g7/sig.RData的链接 在示例中,两列是lat和long,第三列是值。 这是绘制不在网格上的数据的最佳方式吗?

非常感谢任何帮助

library(rgl)
library(reshape)
rgl.clear(type = c("shapes"))
load("sig.RData")
calls = sig
calls=as.matrix(calls)
dimnames(calls) <- list(NULL, c("lat","long","total"))
calls<-as.data.frame(calls)

head(calls)
bin_size = 0.5
calls$long_bin = cut(calls$long, seq(min(calls$long), max(calls$long), bin_size))
calls$lat_bin = cut(calls$lat, seq(min(calls$lat), max(calls$lat), bin_size))
calls$total = log(calls$total) / 3 #need to do this to flatten out totals

calls = melt(calls[,3:5])

calls = cast(calls, lat_bin~long_bin, fun = sum, fill = 0)
calls = calls[,2:(ncol(calls)-1)]
calls = as.matrix(calls)

# simple black and white plot
x = (1: nrow(calls))
z = (1: ncol(calls))
rgl.surface(x, z, calls)
rgl.bringtotop()


rgl.pop()
# nicer colored plot
ylim <- range(calls)
ylen <- ylim[2] - ylim[1] + 1
col <- topo.colors(ylen)[ calls-ylim[1]+1 ]


x = (1: nrow(calls))
z = (1: ncol(calls))

rgl.bg(sphere=FALSE, color=c("black"), lit=FALSE)
rgl.viewpoint( theta = 300, phi = 30, fov = 170, zoom = 0.03)
rgl.surface(x, z, calls, color = col, shininess = 10)
rgl.bringtotop()

0 个答案:

没有答案