【问题标题】:How can i mask the ocean on a map of Australias如何在澳大利亚地图上掩盖海洋
【发布时间】:2013-07-17 21:04:36
【问题描述】:

我想在澳大利亚部分地区的地图中掩盖海洋。

这是我的出发点:

library(maps)
library(mapdata)
image(x=110:155, y =-40:-10, z = outer(1:45, 1:30, "+"), 
  xlab = "lon", ylab = "lat")

然后,按照此处发布的解决方案 (How can I color the ocean blue in a map of the US?),我设置了多路径:

outline <- map("worldHires", plot=FALSE) # returns a list of x/y coords
xrange <- range(outline$x, na.rm=TRUE) # get bounding box
yrange <- range(outline$y, na.rm=TRUE)
xbox <- xrange + c(-2, 2)
ybox <- yrange + c(-2, 2)
# create the grid path in the current device
polypath(c(outline$x, NA, c(xbox, rev(xbox))),
 c(outline$y, NA, rep(ybox, each=2)),
 col="light blue", rule="evenodd")][1]

但是,生成的地块在国家边界的任一侧都被掩盖了。谁能帮我只在国外戴口罩?

【问题讨论】:

  • map("worldHires", regions="australia", bg="light blue", fill=TRUE, xlim=c(110, 155), ylim=c(-40, -10)) 足够了吗?

标签: r map plot mask


【解决方案1】:

感谢此解决方案的 R-help 邮件列表 (https://stat.ethz.ch/pipermail/r-help/2013-July/356943.html):

library(maps)
library(mapdata)

image(x=110:155, y =-40:-10, z = outer(1:45, 1:30, "+"),
  xlab = "lon", ylab = "lat")

明确说明地区名称(“澳大利亚”):

outline <- map("worldHires", regions="Australia", exact=TRUE, plot=FALSE) # returns a list of x/y coords
xrange <- range(outline$x, na.rm=TRUE) # get bounding box
yrange <- range(outline$y, na.rm=TRUE)
xbox <- xrange + c(-2, 2)
ybox <- yrange + c(-2, 2)

从大纲中省略 NA(这是之前干扰路径的原因):

subset <- !is.na(outline$x)

使用轮廓的子集创建多路径(即没有 NA):

# create the grid path in the current device
polypath(c(outline$x[subset], NA, c(xbox, rev(xbox))),
  c(outline$y[subset], NA, rep(ybox, each=2)),
  col="light blue", rule="evenodd")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 2016-10-25
    • 2015-05-03
    • 2016-11-14
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多