Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rworldmap package countrylist

Tags:

r

rworldmap

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.

like image 474
cs0815 Avatar asked Oct 14 '11 11:10

cs0815


2 Answers

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"  
like image 124
Andrie Avatar answered Sep 28 '22 04:09

Andrie


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
like image 37
IRTFM Avatar answered Sep 28 '22 06:09

IRTFM