在使用 R 创建的地理地图中填充大陆地区

发布于 2024-12-07 02:41:19 字数 988 浏览 1 评论 0原文

我尝试使用 R 中的地图包创建地理地图。我不确定这是否是“选择的包”。

我试图画一张蓝色背景、白色大陆地区和红色国家边界的世界地图。但似乎,如果不用黑色绘制国家边界,就不可能填充区域。我的错误是什么?

library(maps)

# Show the World map without country border,
# with black continent boundaries on a bluish background 
map("world", interior=F, boundary=T, bg="#ddeeff", col="black")

# Fill continental areas in white
map("world", col="white", interior=F, fill=TRUE, add=T)

# Add country borders in red
map("world", interior=T, boundary=F, col="red", add=T)

使用 ?map 给我:

fill - 逻辑标志,指示是否绘制线条或填充区域。如果为 FALSE,则将绘制每个区域的边界线(但对于内部线仅绘制一次)。如果为 TRUE,则将使用 col = 参数中的颜色填充每个区域,并且不会绘制边界线。

我的 R 版本是:

平台 x86_64-apple-darwin9.8.0
架构 x86_64
操作系统darwin9.8.0
系统x86_64,darwin9.8.0
状态
主要2
未成年人 13.0
2011年
04 月
第 13 天
svn 修订版 55427
语言 R
version.string R 版本 2.13.0 (2011-04-13)

I try to get into creating geographical maps using the maps-package in R. I'm not sure if this is the "package of choice".

I tried to draw a map of the world with a bluish background, white continental areas and red country borders. But it seems, that it is not possible to fill areas without drawing country borders in black. What is my mistake?

library(maps)

# Show the World map without country border,
# with black continent boundaries on a bluish background 
map("world", interior=F, boundary=T, bg="#ddeeff", col="black")

# Fill continental areas in white
map("world", col="white", interior=F, fill=TRUE, add=T)

# Add country borders in red
map("world", interior=T, boundary=F, col="red", add=T)

Using ?map gives me:

fill - logical flag that says whether to draw lines or fill areas. If FALSE, the lines bounding each region will be drawn (but only once, for interior lines). If TRUE, each region will be filled using colors from the col = argument, and bounding lines will not be drawn.

My R-Version is:

platform x86_64-apple-darwin9.8.0
arch x86_64
os darwin9.8.0
system x86_64, darwin9.8.0
status
major 2
minor 13.0
year 2011
month 04
day 13
svn rev 55427
language R
version.string R version 2.13.0 (2011-04-13)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扬花落满肩 2024-12-14 02:41:19

使用基本图形:(

黑色边界上方有一定量的红色过度绘制 - 我找不到完全消除此问题的方法。)

library(maps)
map("world", interior=TRUE, fill=TRUE, boundary=FALSE, col="white", bg="lightblue")
map("world", interior=TRUE, boundary=TRUE, col="red", add=TRUE)

在此处输入图像描述

使用 ggplot:(

使用 ggplot,您可以完全控制所有颜色,并且不会出现过度绘制。但这需要渲染时间有点长...)

library(ggplot2)
library(maps)
mapWorld <- borders("world", colour="red", fill="white")
ggplot() + 
  mapWorld + 
  geom_path() + 
  opts(
    plot.background=theme_rect(fill="lightblue"),
    panel.background=theme_rect(fill="lightblue")
    )

在此处输入图像描述

Using base graphics:

(There is a certain amount of overplotting of red on top of black boundaries - I couldn't find a way of getting rid of this altogether.)

library(maps)
map("world", interior=TRUE, fill=TRUE, boundary=FALSE, col="white", bg="lightblue")
map("world", interior=TRUE, boundary=TRUE, col="red", add=TRUE)

enter image description here

Using ggplot:

(With ggplot you have full control over all the colours and there is no overplotting. But it takes a bit longer to render...)

library(ggplot2)
library(maps)
mapWorld <- borders("world", colour="red", fill="white")
ggplot() + 
  mapWorld + 
  geom_path() + 
  opts(
    plot.background=theme_rect(fill="lightblue"),
    panel.background=theme_rect(fill="lightblue")
    )

enter image description here

贪恋 2024-12-14 02:41:19

可以在单个“map”命令中更改边框的颜色:

map("world", fill=TRUE, col="white", bg="lightblue", border="red")

“border='red'”选项未在“?map”中明确记录,因为它实际上是直接“polygon()”的选项" 这是从 map() 内部调用的。它是 map() 调用中“...”的一部分。

It is possible to change the color of the borders in a single 'map' command:

map("world", fill=TRUE, col="white", bg="lightblue", border="red")

The "border='red'" option is not documented explicitely in '?map', because it is in fact an option directly for "polygon()" which is called from inside map(). It's part of the "..." in the map() call.

吻泪 2024-12-14 02:41:19

使用基础图形:

为了避免过度绘制,您可以在第一次调用时将lty参数设置为0,以填充国家/地区而不绘制黑色边界。

library(maps)   
map("world", interior=TRUE, fill=TRUE, boundary=FALSE, col="white", lty=0, bg="lightblue")
map("world", interior=TRUE, boundary=TRUE, col="red", add=TRUE)

Using base graphics:

In order to avoid the overplotting, you can set the lty argument to 0 in the first call to fill the countries without drawing the black boundaries.

library(maps)   
map("world", interior=TRUE, fill=TRUE, boundary=FALSE, col="white", lty=0, bg="lightblue")
map("world", interior=TRUE, boundary=TRUE, col="red", add=TRUE)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文