silent_hunter
silent_hunter

Reputation: 2508

Continent names and choropleth maps

I am working with ISO-3 names of the countries. Below you can see one example.I want to use this data for Choropleth map.

    datar <- data.frame(GEO = c("GR","AZ","TR","GA","IR"),
                        Value = c(0.5560,0.323,0.2140,0.312,0.0225),
                        search_countries = factor(c("Greece","Azerbaijan","Turkey","Georgia","Iran")),
                        countries = c("Greece","Azerbaijan","Turkey","Georgia","Iran")
    )
    
map <- map_data('world', region = datar$search_countries)

The code's last line allows me to draw a Choropleth map. Now I want to have an additional column with the continent names for each country next to the column subregion.

enter image description here

So can anybody help me how to solve this problem and to have a continent name for each country on the table?

Upvotes: 0

Views: 140

Answers (1)

Bowhaven
Bowhaven

Reputation: 395

If I understand correctly you want to add a column containing the relevant continents for each country in your dataframe?

Here we can get the country and continent names using the raster package then join them onto your dataframe :)

country.codes <- raster::ccodes()

map.continents <- left_join(map, country.codes, by = c('region' = 'NAME')) %>% 
  select(all_of(colnames(map)), continent)

Upvotes: 1

Related Questions