使用[R]地图包-在世界地图上的特定国家/地区着色 [英] Using [R] maps package - colouring in specific nations on a world map

查看:1070
本文介绍了使用[R]地图包-在世界地图上的特定国家/地区着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建世界地图并为某些国家/地区着色.基本上,我想用红色突出显示一些国家,而用蓝色突出显示其他国家.

I'm trying to create a world map and color certain nations. Basically, I would like to highlight some countries in red and other countries in blue.

如果有人可以帮助我为此生成基本的[R]代码,我将非常感谢!

If someone could help me generate the basic [R] code for this, I would be very thankful!!

推荐答案

如果您不习惯使用maps包,则maptools包中的对象wrld_simpl可以使生成此类地图变得非常容易.为了让您入门,这里有几行代码生成一张世界地图,在世界地图中,名称以字母"U"开头的国家/地区用红色标记:

If you are not hooked on using the maps package, the object wrld_simpl in the maptools package can make producing this sort of map pretty easy. Here, to get you started, are a few lines of code that produce a world map in which nations whose names start with the letter "U" are colored in red:

library(maptools)
data(wrld_simpl)
plot(wrld_simpl, 
     col = c(gray(.80), "red")[grepl("^U", wrld_simpl@data$NAME) + 1])

(wrld_simplSpatialPolygonsDataFrame类的对象,wrld_simple@data中包含的data.frame包括一个NAME列,可用于突出显示所选的任何国家.)

(wrld_simpl is an object of class SpatialPolygonsDataFrame, and the data.frame contained in wrld_simple@data includes a NAME column that you can use to highlight whichever countries you choose.)

这篇关于使用[R]地图包-在世界地图上的特定国家/地区着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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