我对 reshape 和 rgl 很陌生,看看我是否理解正确我正在浏览http://www.r-bloggers.com/creating-3d-geographical-plots-in-r-using-中提供的代码rgl/,它似乎适用于网站中提供的数据集,但不适用于我的,我不明白为什么,但我得到的只是一张灰色图像。这是我的数据集http://www.mediafire.com/download/8ifpssvdyr665g7/sig.RData的链接, 因为在示例中,两列是经纬度,第三列是一个值。这是绘制不在网格上的数据的最佳方法吗?
任何帮助是极大的赞赏
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()