[英]Using [R] maps package - colouring in specific nations on a world map
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. 基本上,我想用红色突出显示一些国家,而用蓝色突出显示其他国家。
If someone could help me generate the basic [R] code for this, I would be very thankful!! 如果有人可以帮助我为此生成基本的[R]代码,我将非常感谢!
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. 如果你不使用钩maps
包,对象wrld_simpl
在maptools
包可以很容易产生这种地图。 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: 为了让您起步,这里有几行代码生成一张世界地图,在世界地图中,名称以字母“ U”开头的国家/地区用红色显示:
library(maptools)
data(wrld_simpl)
plot(wrld_simpl,
col = c(gray(.80), "red")[grepl("^U", wrld_simpl@data$NAME) + 1])
( 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.) ( wrld_simpl
是类的对象SpatialPolygonsDataFrame
,并包含在data.frame wrld_simple@data
包括NAME
栏,你可以用它来无论你选择哪个国家的亮点。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.