Using [R] maps package - colouring in specific nations on a world map

折月煮酒 提交于 2019-11-29 11:01:14

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!