如何用几种颜色和轮廓绘制r中的测深图?

时间:2017-11-29 20:08:47

标签: r plot mapping

我试图在R中创建巴布亚新几内亚的水深测量图,但是当我绘制地图时,它看起来非常忙于所有的轮廓。我想让土地成为一种颜色,而水则成为第二种颜色,因此地图看起来非常简单。我附上了我的r代码和我使用它时创建的地图。

最佳, 香农

library(marmap)
PNG_Map <- getNOAA.bathy(lon1 = 144, lon2 = 158, lat1 = -14, lat2 = -8, 
resolution = 1) 
summary(PNG_Map)
library(zoom)

white <- ("white")
black <- ("black")

par(mfrow=c(1,1))

plot(PNG_Map, image = TRUE, land = TRUE, xlim=c(148.75,154), 
ylim=c(-14, -8.75), xaxs = "i", yaxs = "i", lty = c(1, 1, 1), lwd = 
c(0.6, 0.6, 1.2), bpal = list(c(0, max(PNG_Map), black), 
c(min(PNG_Map),0 , white)))

Map of PNG

2 个答案:

答案 0 :(得分:1)

我强烈建议您多次调用plot.bathy()函数来创建地图,以逐个元素地绘制您想要的内容。这样,您可以根据需要添加尽可能多的等深线。以下是基于代码的两个示例(我删除了不必要的行和参数):

library(marmap)
PNG_Map <- getNOAA.bathy(lon1 = 144, lon2 = 158, lat1 = -14, lat2 = -8, resolution = 1)     

# --- Black and white ---
plot(PNG_Map, image = TRUE, land = TRUE, xlim=c(148.75,154), ylim=c(-14, -8.75), n=100, lwd = 0.03, bpal = list(c(0, max(PNG_Map), grey(.3)), c(min(PNG_Map),0 , "white")))
plot(PNG_Map, deep=0, shallow=0, lwd = 0.6, add=T)  # Add coastline
plot(PNG_Map, deep=-200, shallow=-200, lwd = 0.4, drawlabels=T, add=T)  # Add -200m isobath
plot(PNG_Map, deep=-2000, shallow=-2000, lwd = 0.4, drawlabels=T, add=T)  # Add -2000m isobath


# --- With colors ---
# Creating color palettes
blues <- c("lightsteelblue4", "lightsteelblue3", "lightsteelblue2", "lightsteelblue1")
greys <- c(grey(0.6), grey(0.93), grey(0.99))

plot(PNG_Map, image = TRUE, land = TRUE, xlim=c(148.75,154), ylim=c(-14, -8.75), lwd = 0.03, bpal = list(c(0, max(PNG_Map), greys), c(min(PNG_Map),0 , blues)))
plot(PNG_Map, deep=0, shallow=0, lwd = 1, add=T)  # Add coastline
plot(PNG_Map, deep=-200, shallow=-200, lwd = 0.4, drawlabels=T, add=T)  # Add -200m isobath
plot(PNG_Map, deep=-2000, shallow=-2000, lwd = 0.4, drawlabels=T, add=T)  # Add -2000m isobath

enter image description here enter image description here

第一次调用plot.bathy()时使用的关键参数是:

  • n=:指定要绘制的大量等参线
  • lwd=:指定等深线的宽度

根据lukeA的建议,请检查?plot.bathy以及vignette("marmap")vignette("marmap-DataAnalysis")。这里有很多例子。

答案 1 :(得分:0)

我想你可以这样试试:

pal1 <- list(
  c(min(PNG_Map), 0, "purple", "blue", "lightblue"),
  c(0, max(PNG_Map), "yellow", "brown"))
pal2 <- list(
  c(min(PNG_Map), 0, "blue"),
  c(0, max(PNG_Map), "yellow"))
plot_it <- function(pal, n, ...) {
  plot(PNG_Map, image=TRUE, land = TRUE, bpal = pal, n = n,
       xlim=c(148.75,154), ylim=c(-14, -8.75), ...)
}
par(mfrow = c(3, 1), mar = c(0,0,0,0), bty="n", xaxt="n", yaxt="n")
plot_it(pal1, 1)
plot_it(pal2, 10)
plot_it(pal2, 10, deep=min(PNG_Map), shallow=0, step = 1000)

enter image description here

同时检查?plot.bathy以获取文档。