【问题标题】:Fill continental areas in geographical maps created with R在使用 R 创建的地理地图中填充大陆区域
【发布时间】:2011-09-29 13:42:13
【问题描述】:

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

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

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)

【问题讨论】:

    标签: r geolocation maps plot geocoding


    【解决方案1】:

    使用基础图形:

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

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        【解决方案3】:

        使用基础图形:

        为了避免过度绘制,您可以在第一次调用中将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)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-09-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-10-05
          • 1970-01-01
          相关资源
          最近更新 更多