phl*_*lot 21 maps r r-maptools rworldmap
我想用R来生成一个非常基本的世界地图,其中一组特定的国家用红色填充,表明它们是疟疾流行国家.
我在数据框中列出了这些国家/地区的列表,但我正在努力将它们叠加在世界地图上.
我已尝试使用该wrld_simpl对象以及包中的joinCountryData2Map方法rworldmap.
我会评论这个答案,以防止增加一个可能多余的问题,但我目前没有足够的声誉,为此道歉.
我很难理解plot()命令的参数- 我想知道是否有一种简单的方法告诉R在wrld_simpl地图上列出我的列表中的所有国家名称而不是使用grepl()等等.
plot(wrld_simpl, 
     col = c(gray(.80), "red")[grepl("^U", wrld_simpl@data$NAME) + 1])
Ben*_*nes 21
使用该rworldmap包,您可以使用以下内容:
library(rworldmap)
theCountries <- c("DEU", "COD", "BFA")
# These are the ISO3 names of the countries you'd like to plot in red
malDF <- data.frame(country = c("DEU", "COD", "BFA"),
  malaria = c(1, 1, 1))
# malDF is a data.frame with the ISO3 country names plus a variable to
# merge to the map data
malMap <- joinCountryData2Map(malDF, joinCode = "ISO3",
  nameJoinColumn = "country")
# This will join your malDF data.frame to the country map data
mapCountryData(malMap, nameColumnToPlot="malaria", catMethod = "categorical",
  missingCountryCol = gray(.8))
# And this will plot it, with the trick that the color palette's first
# color is red
编辑:添加其他颜色,包括图片
## Create multiple color codes, with Burkina Faso in its own group
malDF <- data.frame(country = c("DEU", "COD", "BFA"),
  malaria = c(1, 1, 2))
## Re-merge
malMap <- joinCountryData2Map(malDF, joinCode = "ISO3",
  nameJoinColumn = "country")
## Specify the colourPalette argument
mapCountryData(malMap, nameColumnToPlot="malaria", catMethod = "categorical",
  missingCountryCol = gray(.8), colourPalette = c("red", "blue"))
Sun*_*nny 13
尝试使用googleVis包并使用gvisGeoMap函数
例如
G1 <- gvisGeoMap(Exports,locationvar='Country',numvar='Profit',options=list(dataMode='regions'))
plot(G1)
    library(maptools)
    data(wrld_simpl)
    myCountries = wrld_simpl@data$NAME %in% c("Australia", "United Kingdom", "Germany", "United States", "Sweden", "Netherlands", "New Zealand")
    plot(wrld_simpl, col = c(gray(.80), "red")[myCountries+1])