Saturday, April 6, 2013

RG#15: how to fill heatmap (color gradient) in map based on quantitative data

We need to get map files (which can be done from http://gadm.org). The following map is Canadian administrative map.  Similarly we can get map for other countries, even less well known. We can download from the website (gadm.org/country) and select file format to R (spartialpolygonsdataframe). Then read the downloaded Rdata file or directly from website using url like the following example (you need to know the name of Rdata file - usually country code followed by level of details)





# following packages need to installed before loading
 require(maps)
require(maptools)

 library(RColorBrewer)
library(sp)


# get the map; may need sometime to be loaded 
con <- url("http://gadm.org/data/rda/CAN_adm1.RData")
print(load(con))
close(con)


# from your data file working directory 
## load ("CAN_adm1.RData")

# data 
 gadm$NAME_1 # will display name of province in order. 
# data to be plotted 
value <- c(45, 15,8, 400, 300,120,22,10, 50,13,0,4,0)
gadm$value <- value
 plotd <- gadm$value

# plotting 
# color brewing 
# we want nine color in yellow orange and red 
 ncolor <- 9
 plotclr <- brewer.pal(ncolor,"YlOrRd")# brew new color



# we want to make classes out of the data, install package classInt  
require(classInt)
class <- classIntervals(plotd, ncolor, style="quantile")
colcode <- findColours(class, plotclr)


# plotting map 
 spplot(gadm, "value", col.regions=plotclr, at=round(class$brks, digits=1), main="Canada map with var plotted" )




List of countries

Afghanistan
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antigua and Barbuda
Argentina
Armenia
Aruba
Australia
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bermuda
Bhutan
Bolivia
Bosnia-Herzegovina
Botswana
Bouvet Island
Brazil
Brunei
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Canada
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Congo, Democratic Republic of the (Zaire)
Congo, Republic of
Cook Islands
Costa Rica
Croatia
Cuba
Cyprus
Czech Republic
Denmark
Djibouti
Dominica
Dominican Republic
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Falkland Islands
Faroe Islands
Fiji
Finland
France
French Guiana
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe (French)
Guam (USA)
Guatemala
Guinea
Guinea Bissau
Guyana
Haiti
Holy See
Honduras
Hong Kong
Hungary
Iceland
India
Indonesia
Iran
Iraq
Ireland
Israel
Italy
Ivory Coast (Cote D`Ivoire)
Jamaica
Japan
Jordan
Kazakhstan
Kenya
Kiribati
Kuwait
Kyrgyzstan
Laos
Latvia
Lebanon
Lesotho
Liberia
Libya
Liechtenstein
Lithuania
Luxembourg
Macau
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique (French)
Mauritania
Mauritius
Mayotte
Mexico
Micronesia
Moldova
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands
Netherlands Antilles
New Caledonia (French)
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
North Korea
Northern Mariana Islands
Norway
Oman
Pakistan
Palau
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn Island
Poland
Polynesia (French)
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russia
Rwanda
Saint Helena
Saint Kitts and Nevis
Saint Lucia
Saint Pierre and Miquelon
Saint Vincent and Grenadines
Samoa
San Marino
Sao Tome and Principe
Saudi Arabia
Senegal
Serbia
Seychelles
Sierra Leone
Singapore
Slovakia
Slovenia
Solomon Islands
Somalia
South Africa
South Georgia and South Sandwich Islands
South Korea
Spain
Sri Lanka
Sudan
Suriname
Svalbard and Jan Mayen Islands
Swaziland
Sweden
Switzerland
Syria
Taiwan
Tajikistan
Tanzania
Thailand
Timor-Leste (East Timor)
Togo
Tokelau
Tonga
Trinidad and Tobago
Tunisia
Turkey
Turkmenistan
Turks and Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United Kingdom
United States
Uruguay
Uzbekistan
Vanuatu
Venezuela
Vietnam
Virgin Islands
Wallis and Futuna Islands
Yemen
Zambia
Zimbabwe


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.