r - 在用 R 创建的地理 map 中填充大陆区域

标签 r geolocation maps plot geocoding

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

我试着画了一张世界地图,背景是蓝色的,大陆地区是白色的,国家边界是红色的。但似乎不绘制黑色国家边界就无法填充区域。我的错误是什么?

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 - 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.

我的 R 版本是:

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)

最佳答案

使用基础图形:

(在黑色边界之上有一定数量的红色过度绘制 - 我找不到完全摆脱这种情况的方法。)

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

使用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")
    )

enter image description here

关于r - 在用 R 创建的地理 map 中填充大陆区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7598223/

相关文章:

r - 有序因子导致 sapply(df, class) 返回列表而不是向量

ios - 开始工作 Ionic + ngCordova + 后台地理定位

javascript - Google map Javascript API 查看位置

r - as(x, 'double' ) 和 as.double(x) 不一致

r - 在列表中获取匹配索引的快速方法

react-native - 2020 年使用 react-native + Expo 在后台跟踪位置的最佳方法

javascript - AngularJS |根据地理位置(纬度、经度)对 JSON 进行排序

android - Phonegap 打开导航器 err_unknown_url_scheme

html - 如何在 CSS 中更改或调用 svg clippath 多边形属性

r - 图 同一图 Igraph 上子图社区的集合