2014-02-21 5 views
0

내 플롯에 특별한 범위의 상자를 추가하고 싶습니다.R에서 levelplot을 사용하여 상자 레이어를 추가하는 방법은 무엇입니까?

 gh <- raster() 
    gh[] <- 1:ncell(gh) 
    SP <- spsample(Spatial(bbox=bbox(gh)), 10, type="random") 

그런 다음 그들에게

levelplot(gh, col.regions = rev(terrain.colors(255)), cuts=254, margin=FALSE) + 
    layer(sp.points(SP, col = "red")) 

이가 여러 십자가와 맵을 나타내는 음모하지만 난 공간적 범위와 상자 플롯해야합니다

 extent(gh) = extent(c(xmn=-180,xmx=180,ymn=-90,ymx=90)) 
     e6 <- extent(2 , 8 , 45 , 51 ) 

enter image description here

나는 coordinates와 플롯에 e6을 추가하고 box.Any 힌트 내부에 수 2를 넣어

답변

1

SpatialPolygonsExtent 개체를 변환하십시오, 그 중심을 추출 완 :

library("raster") 
library("sp") 
library("rasterVis") 

gh <- raster() 
gh[] <- 1:ncell(gh) 
SP <- spsample(Spatial(bbox=bbox(gh)), 10, type="random") 

e6 <- extent(2, 8, 45, 51) 
e6pol <- as(e6, 'SpatialPolygons') 
centroid <- coordinates(e6pol) 

levelplot(gh, col.regions = rev(terrain.colors(255)), cuts=254, margin=FALSE) + 
    layer({sp.points(SP, col = "red") 
      sp.polygons(e6pol) 
      panel.text(centroid[,1], centroid[,2], '2') 
      }) 

result

+0

고맙습니다. 상자 안의 숫자 2의 zise를 조절하는 방법 – sacvf

+1

'panel.text' 안에'cex'를 사용하십시오. 세부 사항은'? panel.text'에서 찾을 수 있습니다. –

관련 문제