2016-08-13 2 views
2

저는 RasterStack에서 8 개의 맵 패널을 가지고 있으며 플롯에 100km 눈금 막대를 추가하려고합니다. 나는 spplot 함수 내에서 sp.layout 함수를 사용하여 래스터 상단에 SpatialLines 객체를 추가했으며, 스케일 막대 (또는 북쪽 화살표)에서도 동일하게 사용할 수 있다고 가정했지만 아무 것도 작동하지 않습니다.spplot의 단일 패널에 눈금 막대를 추가하는 방법

I가 사용하고있는 코드이다

library(sp) 
library(raster) 
library(grid) 

spplot(rasterstack, layout=c(2,4), 
     names.attr=c("a", "b", "c", "d", "e", "f", "g", "h"), 
     between=list(x=1, y=1), 
     at=seq(0,1000,by=100), 
     col.regions=colorRampPalette(c("grey90","yellow4","green4"))(100), 
     par.strip.text=list(cex=2.5), 
     scales=list(draw=F), 
     colorkey=list(labels=list(labels=seq(0,1,by=0.25), 
           at=seq(0,1000,by=250), 
           width=10, cex=2.5)), 
     sp.layout=list(list(country, first=FALSE), # add country borders 
         list(spatiallines, lwd=1.5, col=4))) 
# Label vertical colorkey 
grid::grid.text('Probability of occurrence', y=unit(0.5,"npc"), x=unit(0.95,"npc"), rot=90, gp=gpar(cex=3, font=2)) 
rasterstack 8 레이어와 RasterStack 및 0 내지 1000, 각 셀 영역의 값 및 country

spatiallines SpatialLines은 *

개체

저는 스케일 바를 추가하기위한 다양한 기능을 보았습니다. layout.scale.bar(), maps::map.scale()scalebar()이지만, 나는 이것을 사용하는 코드 spplot에 통합하는 방법을 알 수 없습니다. 나는 그들을 spplot에 인수로 추가하려고 시도했거나 sp.layout=list() 인수 안에리스트로 추가하려고했지만 어느 것도 작동하지 않습니다.

감사합니다.

답변

0

출력이 SpatialPolygons이기 때문에 layout.scale.bar()layout.north.arrow()을 권장합니다. 레이아웃 함수의 이름은 "SpatialPolygonsRescale"이며 목록의 첫 번째 인수로 지정해야합니다.

여기가 제 예입니다.

library(sp); library(raster); library(grid) 

### example data 
r <- raster(system.file("external/test.grd", package="raster")) 
range(r) # 178400, 181600, 329400, 334000 (xmin, xmax, ymin, ymax) 
r4 <- stack(r, r, r, r) 

### preparation of scalebar etc. 
North <- list("SpatialPolygonsRescale", layout.north.arrow(type=1), 
       offset = c(178600, 333000), scale = 800, which = 1) 

North2 <- list("SpatialPolygonsRescale", layout.north.arrow(type=2), 
       offset = c(178600, 332000), scale = 1200, fill="gray", which = 2) 

scale1 <- list("SpatialPolygonsRescale", layout.scale.bar(), 
       offset = c(180500, 329800), scale = 500, fill=c("transparent","black"), which = 3) 
s1_text0 <- list("sp.text", c(180500, 329800 + 150), "0", cex = .5, which = 3) 
s1_text1 <- list("sp.text", c(180500 + 500, 329800 + 150), "500 m", cex = .5, which = 3) 

scale2.1 <- list("SpatialPolygonsRescale", layout.scale.bar(height=0.1), 
       offset = c(178600, 333000), scale = 1000, fill=c("red", "green"), which = 4) 
s2.1_text0 <- list("sp.text", c(178600, 333000 - 150), "0", cex = .5, which = 4) 
s2.1_text1 <- list("sp.text", c(178600 + 1000, 333000 - 150), "1 km", cex = .5, which = 4) 

scale2.2 <- list("SpatialPolygonsRescale", layout.scale.bar(), 
       offset = c(178600, 333200), scale = 2000, fill=c("cyan", "violet"), which = 4) 
s2.2_text0 <- list("sp.text", c(178600, 333200 + 300), "0", cex = .5, which = 4) 
s2.2_text1 <- list("sp.text", c(178600 + 2000, 333200 + 300), "2000 m", cex = .5, which = 4) 
    # Of course, you can write 180600 instead of 178600 + 2000 

### draw 
spplot(r4, layout=c(2,2), 
     sp.layout = list(North, North2, scale1, s1_text0, s1_text1, 
         scale2.1, s2.1_text0, s2.1_text1, scale2.2, s2.2_text0, s2.2_text1)) 

enter image description here

관련 문제