【发布时间】:2014-09-24 14:56:28
【问题描述】:
我正在尝试使用格子构建一个不受县或人工边界限制的地理空间连续热图,很像 Katz 的 Dialect Maps,与 Choropleth Challenge 有点不同。
到目前为止,我已经很接近了,但我一直在努力弄清楚如何避免在地理区域以外的区域显示热图颜色。请参见下面的示例:
library(maps)
library(lattice)
# get region border coordinates for the contiguous USA
m <- map("usa")
# make a grid of latitude and longitude, and supply z-values
lons <- seq(min(m$x, na.rm=T), max(m$x, na.rm=T), length.out=30)
lats <- seq(min(m$y, na.rm=T), max(m$y, na.rm=T), length.out=30)
pts <- expand.grid(lons, lats)
names(pts) <- c("lon", "lat")
pts$z <- sin(pts$lat*pi/180) + cos(pts$lon*pi/180)
## (A) eliminate z-values outside of the USA region
# pts$z[ lat & lon outside of region ] <- NA # don't know how to do this
# this could work, but would leave jagged edges around the region border
levelplot(z~lon*lat, pts, aspect="xy",
panel = function(...){
panel.levelplot(...)
panel.xyplot(m$x, m$y, type="l", col="black") # adds USA border
# (B) fill the area outside region with white
# panel.something() # not sure what to use here
})
方法 (B) 可能会很好,但我没有看到一个简单的方法来做到这一点。有什么想法吗?
【问题讨论】:
-
这可能会有所帮助:r-sig-geo.2731867.n2.nabble.com/…