仅在没有尼日利亚 r 地图的情况下绘制尼日尔时出现问题
Trouble plotting Niger only without Nigeria r maps
我正在尝试在地图包中的 map() 中填写尼日尔国家。我知道除非您指定,否则以某些字母开头的特定国家/地区将全部绘制,但我无法在不绘制尼日利亚的情况下仅绘制尼日尔。
library(maps)
#plot map of Africa
map(database = "world", regions = ".", xlim = c(-20,60), ylim = c(-40,40), wrap = FALSE, resolution = 2, type = "l", bg = par("bg"), myborder = 0.01)
# fills in Nigeria alone
map(regions = 'Nigeria',fill = TRUE, add = TRUE, col = 'green')
#fills in the countries of Niger AND Nigeria
map(regions = 'Niger',fill = TRUE, add = TRUE, col = 'gray')
阅读 'maps' 文档并找到 this question 后,我查看了 'countrycode' 包中的 countrycode_data
国家列表,我找到了正则表达式 \bniger(?!ia)
我认为这是我问题的一部分。我对任何其他以相同字母或单词开头的国家都有同样的问题,例如 "Guinea," "Papua New Guinea," 和 "Guinea-Bissau." 如何只绘制最简单的版本国家名称? None 包国家代码中的代码在地图上单独绘制了尼日尔。
根据 maps 库中的 map()
描述 manual :
exact : If TRUE , only exact matches with regions are selected for
drawing. If FALSE , each element of regions is matched as a regular
expression against the polygon names in the database and all matches
are selected for drawing.
只需要将 exact=TRUE
设置为:
map(regions = 'Niger', exact=TRUE, fill = TRUE, add = TRUE, col = 'gray')
产生所需的结果
我正在尝试在地图包中的 map() 中填写尼日尔国家。我知道除非您指定,否则以某些字母开头的特定国家/地区将全部绘制,但我无法在不绘制尼日利亚的情况下仅绘制尼日尔。
library(maps)
#plot map of Africa
map(database = "world", regions = ".", xlim = c(-20,60), ylim = c(-40,40), wrap = FALSE, resolution = 2, type = "l", bg = par("bg"), myborder = 0.01)
# fills in Nigeria alone
map(regions = 'Nigeria',fill = TRUE, add = TRUE, col = 'green')
#fills in the countries of Niger AND Nigeria
map(regions = 'Niger',fill = TRUE, add = TRUE, col = 'gray')
阅读 'maps' 文档并找到 this question 后,我查看了 'countrycode' 包中的 countrycode_data
国家列表,我找到了正则表达式 \bniger(?!ia)
我认为这是我问题的一部分。我对任何其他以相同字母或单词开头的国家都有同样的问题,例如 "Guinea," "Papua New Guinea," 和 "Guinea-Bissau." 如何只绘制最简单的版本国家名称? None 包国家代码中的代码在地图上单独绘制了尼日尔。
根据 maps 库中的 map()
描述 manual :
exact : If TRUE , only exact matches with regions are selected for drawing. If FALSE , each element of regions is matched as a regular expression against the polygon names in the database and all matches are selected for drawing.
只需要将 exact=TRUE
设置为:
map(regions = 'Niger', exact=TRUE, fill = TRUE, add = TRUE, col = 'gray')
产生所需的结果