How to create a world map in R with specific countries filled in?

怎甘沉沦 提交于 2019-11-27 22:46:07

Using the rworldmap package, you could use the following:

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

EDIT: Add other colors and include picture

## 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"))

Sunny Sunny

Try using googleVis package and use gvisGeoMap Functions

e.g.

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])

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