如何在美国地图上为海蓝色? [英] How can I color the ocean blue in a map of the US?

查看:158
本文介绍了如何在美国地图上为海蓝色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图像上绘制美国地图,然后填写海洋。

I would like to draw a map of the US over an image, but then fill in the oceans.

这是我的起点:

library(maps)
library(graphics)
image(x=-90:-75, y = 25:40, z = outer(1:15, 1:15, "+"), 
      xlab = "lon", ylab = "lat")
map("state", add = TRUE)

但我希望大西洋和墨西哥湾能够填充纯色。

But I would like the Atlantic Ocean and Gulf of Mexico to be filled in a solid color.

推荐答案

好问题!这个怎么样?

Good question! How's this?

library(maps)
image(x=-90:-75, y = 25:40, z = outer(1:15, 1:15, "+"), 
      xlab = "lon", ylab = "lat")
map("state", add = TRUE)

library(grid)
outline <- map("usa", 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")

I在阅读了Paul Murrell( grid 背后的男人)关于网格路径的最新R-Journal文章之后,我遇到了这个问题的解决方案(pdf here)

I came across the solution to this problem after reading Paul Murrell's (the man behind grid) recent R-Journal article on grid paths (pdf here).

记住:


这不是你画的,不是你画的-Paul Murrell(R Journal Vol。 4/2)

"It’s Not What You Draw, It’s What You Don’t Draw" -Paul Murrell (R Journal Vol. 4/2)

这篇关于如何在美国地图上为海蓝色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆