2017-04-21 2 views
1

나는 해양 보호 구역에 대한 그림이 marmap이지만 매우 확대되어있어 매사추세츠 주에있는 미국 주 그림을 포함하려고합니다.Map in MarMap/ggplot2의 marmap 파일 포함

library(marmap) 
stellie <- getNOAA.bathy(lon1 = -70.8, lon2 = -69.9, 
         lat1 = 42.8, lat2 = 41.7, resolution = 1) 
#area for marine sanctuary 

blues <- colorRampPalette(c("purple","blue","cadetblue1","white")) 
greens <- colorRampPalette(c("#00CC00", "#33CC33", "#009900", "#006633")) 

#custom colours 

plot(stellie, image = TRUE, land = TRUE, lwd = 0.4, 
    bpal = list(c(0, max(stellie), greens(100)), 
        c(min(stellie),0,blues(100))), 
    drawlabel = c(TRUE, FALSE, FALSE)) 
scaleBathy(stellie, deg = 0.17, x = "bottomleft", inset = 5) 

#final plot 

와 나는 보스턴이 더 큰 영역이 삽입 포함, 또는 최초의지도

boston <- getNOAA.bathy(lon1 = -72, lon2 = -69.7, 
         lat1 = 43, lat2 = 41.3, resolution = 1) 
plot(boston, image = TRUE, land = TRUE, lwd = 0.4, 
    bpal = list(c(0, max(boston), greens(100)), 
      c(min(boston),0,blues(100))), 
    drawlabel = c(TRUE, FALSE, FALSE)) 

함께 나는이이 그림 갖고 싶어 :

현재, 다음과 같이 내 코드입니다 아마 ggplot에서 잘 했으므로 도시 이름을 포함 할 수 있지만 marmap 파일을 ggplot으로 가져 오는 방법을 모르겠습니다.

답변

0

this paper from Marine Biology에서 나는 그림 1이 당신이 성취하고자하는 바를 정확히 생각합니다. 그래서 여기에이 맵을 만드는데 사용 된 스크립트 나 적어도 스크립트의 관련 라인이 있습니다. (주의 : 데이터 세트는 꽤 무겁습니다.) 여기서 핵심은 gridgridBase 패키지를 사용하여 viewports을 만드는 것입니다. 각 viewport은 고유 한 좌표 세트를 사용하여 구별되는 플롯을 호스팅 할 수 있습니다. 여기

# Load appropriate packages 
library(raster) ; library(marmap) ; library(gridBase) ; library(grid) 

# Get bathy for the world with a decent resolution (careful: ca. 21 Mo) 
world <- getNOAA.bathy(-180, 180, -90, 90, res = 15, keep = TRUE) 

# Get bathy for the study area with a 1 min resolution (careful: ca. 75 Mo) 
bath <- getNOAA.bathy(35, 60, -25, 0, res = 1, keep = TRUE) 

# Switch to raster, project, and go back to bathy object for the world map (rgdal needed) 
world.ras <- marmap::as.raster(world) 
ma.proj <- "+proj=ortho 
       +lat_0=0 
       +lon_0=50 
       +x_0=0 
       +y_0=0" 
world.ras.proj <- projectRaster(world.ras,crs = ma.proj) 
world.proj <- as.bathy(world.ras.proj) 

# Prepare color palettes 
blues <- c(grey(.98)) 
greys <- c(grey(0.6), grey(0.93), grey(0.99)) 


# Make a nice plot... 

    ### First, plot the study area 
    plot.new() 
    pushViewport(viewport()) 

    par(mar = c(4, 4, 1, 1)) 
    plot(bath, image = TRUE, land = TRUE, lwd = 0.05, bpal = list(c(0, max(bath), greys), c(min(bath),0,blues)),asp=1, las=1) 
    plot(bath, deep = 0, shallow = 0, step = 0, lwd = 0.7, add = TRUE) # Coastline 
    plot(bath, deep = -200, shallow = -200, step = 0, lwd = 0.5, draw=FALSE, add = TRUE) # -200m isobath 
    plot(bath, deep = -1000, shallow = -1000, step = 0, lwd = 0.5, draw=FALSE, add = TRUE) # -1000m isobath 
    scaleBathy(bath, deg=4.91, x=37, y=-24) 

    ### Then, insert a world map on the top right corner 
    pushViewport(viewport(x = 0.67, y = 0.97, width = 0.3, height = 0.3, just = c("left", "top"))) 
    grid.rect(gp = gpar(fill = "white", lwd = 0.5)) 
    par(plt = gridPLT(), bg = "white", new = TRUE) 

    blues <- grey(.95) 

    ### Plot worldmap: needs the "fixed" palette.bathy from v0.9 (na.rm=TRUE added in several places) 
    plot(world.proj, image = TRUE, land = TRUE, n=0, lwd = 0.01, las = 1, bpal = list(c(0, max(world.proj, na.rm = T), grey(0.6), grey(0.99)), c(min(world.proj, na.rm = T), 0, blues)), asp = 1, axes = FALSE, xlab = "", ylab = "") 
    plot(world.proj, deep = 0, shallow = 0, step = 0, lwd = 0.4, add = TRUE) 

    ### add a frame with shadow 
    n <- -30000 ; m <- -50000 # Shadow offset 
    rect(-1290466 + n, -2648928.4 + m, 768012 + n, -590145.2 + m, border = col2alpha(1, .08), lwd = 7) 
    rect(-1290466 + n, -2648928.4 + m, 768012 + n, -590145.2 + m, border = col2alpha(1, .08), lwd = 6) 
    rect(-1290466 + n, -2648928.4 + m, 768012 + n, -590145.2 + m, border = col2alpha(1, .08), lwd = 5) 
    rect(-1290466 + n, -2648928.4 + m, 768012 + n, -590145.2 + m, border = col2alpha(1, .08), lwd = 4) 
    rect(-1290466 + n, -2648928.4 + m, 768012 + n, -590145.2 + m, border = col2alpha(1, .08), lwd = 3) 
    rect(-1290466, -2648928.4, 768012, -590145.2, border = 1, lwd = 2) 

그리고

는 결과입니다 marmap의 이후 버전에서 enter image description here

,이 더 간단하게 할 계획이다. 하지만 지금은 그게 전부입니다!