rworldmap package countrylist
Asked Answered
F

5

12

Is there a way to obtain the list of countries, regions (?) and continents the rworldmap package supports when I want to join data?

I did some google searches and am just starting off with R.

Thanks.

Fastigiate answered 14/10, 2011 at 11:0 Comment(4)
What is rworldmap? In which package did you find this?Deportment
Its an R package: cran.r-project.org/web/packages/rworldmap/index.html I have edited the question to make things hopefully clearer.Fastigiate
I presume you've read the two package vignettes that you can find on the page you link to? These seem to contain lots of useful examples and FAQs.Deportment
Yes I do/did. It does not contain a list of 'supported' countries or how to access then though or do you see it?Fastigiate
D
10

It seems to me the rworldmap package provides some additional functionality on top of the maps package.

If this is indeed the case, you can do the following:

library(maps)
x <- map("world", plot=FALSE)
str(x)
List of 4
 $ x    : num [1:27121] -130 -130 -132 -132 -132 ...
 $ y    : num [1:27121] 55.9 56.1 56.7 57 57.2 ...
 $ range: num [1:4] -180 190.3 -85.4 83.6
 $ names: chr [1:2284] "Canada" "South Africa" "Denmark" "Great Lakes:Superior, Huron, Michigan" ...
 - attr(*, "class")= chr "map"

This extracts the maps database, and the element names contains the name for each map polygon. These names are in fact a multi-level list where the elements are separated by colons. For example, to get the list of polygons belonging to the UK:

x$names[grep("UK", x$names)]
 [1] "UK:Gibralter"                         
 [2] "UK:Scotland:Isle of Lewis"            
 [3] "UK:Pitcairn Island"                   
 [4] "UK:Guernsey"                          
 [5] "UK:Great Britain"                     
 [6] "UK:Scotland:Shetland Islands:Unst"    
 [7] "UK:Saint Mary's"                      
 [8] "UK:Scotland:Shetland Islands:Yell"    
 [9] "UK:Northern Ireland"                  
[10] "UK:Bermuda"                           
[11] "UK:Tristan da Cunha Island"           
[12] "UK:Scotland:Saint Kilda"              
[13] "UK:Scotland:Ruhm"                     
[14] "UK:Scotland:Benbecula"                
[15] "UK:Scotland:North Uist"               
[16] "UK:Saint Helena Island"               
[17] "UK:Scotland:Island of Skye"           
[18] "UK:Scotland:Barra"                    
[19] "UK:Scotland:Island of Mull"           
[20] "UK:Henderson Island"                  
[21] "UK:Isle of Sheppey"                   
[22] "UK:Jersey"                            
[23] "UK:Scotland:Coll"                     
[24] "UK:Scotland:Jura"                     
[25] "UK:Scotland:Island of Arran"          
[26] "UK:Scotland:Tiree"                    
[27] "UK:Scotland:Islay"                    
[28] "UK:Ascension Island"                  
[29] "UK:Scotland:Colonsay"                 
[30] "UK:Scotland:Shetland Islands:Mainland"
[31] "UK:Scotland:South Uist"               
[32] "UK:Scotland:Orkney Islands:Hoy"       
[33] "UK:Gough Island"                      
[34] "UK:Scotland:Orkney Islands:Mainland"  
Deportment answered 14/10, 2011 at 11:39 Comment(0)
S
5

Looking at one of the vignettes it appears that this should work:

require(rworldmap)
data(countryExData)
countries <- countryExData[, 2]
EPI_regions <- countryExData[, 3]
GEO_regions <- countryExData[, 4]

If you wanted to get the continental divisions taught in grammar school then there would be further processing needed on the GEO_regions:

> countryExData[ 1:10, 2:4]
                            Country                  EPI_regions
1                            Angola           Sub-Saharan Africa
2                           Albania    Central and Eastern Europ
3  United Arab Emirates             Middle East and North Africa
4                         Argentina    Latin America and Caribbe
5                           Armenia Middle East and North Africa
6                         Australia    East Asia and the Pacific
7                           Austria                       Europe
8                        Azerbaijan    Central and Eastern Europ
9                           Burundi           Sub-Saharan Africa
10                          Belgium                       Europe
             GEO_subregion
1          Southern Africa
2           Central Europe
3        Arabian Peninsula
4            South America
5           Eastern Europe
6  Australia + New Zealand
7           Western Europe
8           Eastern Europe
9           Eastern Africa
10          Western Europe
Stammel answered 14/10, 2011 at 12:17 Comment(1)
FYI there are are only 149 countries in countryExData. There are 195 countries total and loads of independent territories. If you want also these, avoid countryExData and instead use countrySynonyms which is also available in rworldmaps countrySynonyms$name1 will get you all of the names, but it may be worth getting the rest of the alternate names countrySynonyms$name2 and countrySynonyms$name3 etc.Jalapa
A
3

I'm reasonably sure that the names are not the same as in the maps package. You can get a list of names and codes with this code.

library(rworldmap)
temp_map = getMap(resolution='coarse')
temp_map@data

The names are in temp_map@data[['NAME']]. However, it's a good idea to use one of the ISO code sets if you can. Names are extremely inconsistent between data sets, and sometimes frustrating differences will break it. For example, Cote d'Ivoire can be given with or without the circumflex, and the circumflex is sometimes encoded differently even though it is displayed the same.

Attempt answered 11/1, 2013 at 22:10 Comment(0)
E
0

Take a look at the map_data function in ggplot2. It converts R maps to data.frames.

Eringo answered 14/10, 2011 at 12:25 Comment(0)
O
0

I got an error that led me to this solution getMap()$NAME

Overlarge answered 24/11, 2015 at 2:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.