2014-09-11 27 views
1

我正在使用spplot繪製R中德國地區的一些數據。 - 工作正常。在R中使用不同圖層繪製地圖

爲了便於理解/閱讀地圖或查找地點,我現在想添加聯邦州的邊界。地圖來自German Borders

我使用readShapeSpatial來加載數據,然後使用spplot和圖層來繪製地圖。但是,我不確定

krs <- readShapeSpatial("VG250_Kreise.shp") 
bdl <- readShapeSpatial("VG250_Bundeslaender.shp") 

[email protected]$n <- cut(rnorm(402, 0, 1), breaks=5) 
seq.red <- rev(sequential_hcl(n=nlevels([email protected]$n), h=0)) 
spplot(krs, "n", col=grey(.9), col.regions=seq.red, pretty=TRUE)+ 
layer(sp.polygons(bdl)) 

我不確定bdl的哪個部分需要添加以獲取邊框。

我非常感謝您的幫助!

謝謝!

+0

注:請不要使用'readShapeSpatial',使用'rgdal 'package和'readOGR'函數 - 讀入shapefile中任何被readShapeSpatial忽略的投影信息。 – Spacedman 2014-09-17 11:00:56

回答

0

要重疊繪製,您可以使用sp.layout參數,請參閱this relevant question。所以你的情況,你會添加如下代碼:

bunder<-list("sp.polygons", bdl) 
spplot(krs, "n", col=grey(.9), col.regions=seq.red, pretty=TRUE, 
     sp.layout=bunder) 

它會給你以下地區分佈:

enter image description here

+0

太棒了!這樣可行!!!謝謝! – coolcats 2014-09-19 09:42:49