[R-sig-Geo] Global mapping of multiple categories by colour

Roger Bivand Roger.Bivand at nhh.no
Wed Aug 28 22:33:01 CEST 2013


On Wed, 28 Aug 2013, Rhona Govender wrote:

> Dear All,
>
> Sorry for cross posting, I have been kindly directed here by the r help group.
>
> I have to make a last minute global map. I'm trying to do this in r,
> but I am a beginner.
>
> I have a global dataset of dependent values (eg. rate of common cold)
> for 100/240 countries/offshore territories. I have a predictor
> variable (eg. Human development index or HDI). What I would like to do
> is colour a global map by HDI grouping (low [0-0.5], medium[0.51-0.7],
> high[0.71-1.0]). So for countries that I have data for, if it is low
> HDI it would be colour1, medium colour 2, low colour3. For countries
> with no data they will be a fourth colour (grey).
>
> Additionally, some small island nations will be too small to be
> visualized. Is there a way to manually increase the size of the
> colouration to be visible on a map at the global scale?
>
> My data is as such (where blanks are no data):
>
> Country HDI Colds Albania 0.42 .72 Austria 0.89 China 0 .76 .12
>
> I have found this example to try and build off:
>
> http://stackoverflow.com/questions/11225343/how-to-create-a-world-map-in-r-with-specific-countries-filled-in?rq=1

This refers briefly to the rworldmap package. Go rather to the package 
page:

http://cran.r-project.org/web/packages/rworldmap/index.html

and review the vignettes and the reference manual. Try to get the examples 
in the manual to work, then try to make your data look like the 
data objects in the examples. See also Andy South's useR! 2013 tutorial:

http://www.edii.uclm.es/~useR-2013//Tutorials/South.html

and his site: http://andysouth.co.uk/ with links to tutorial and talk 
materials.

Summary: make an example work with Andy's data; make your data look like 
his; re-run the example with your data.

Hope this helps,

Roger

>
> To change this example, I imported my csv, picked out the columns I
> wanted (country ISO3 codes [country] and the hdi predictor[hdi]) and
> named them(country=data3$country) then and made it into a data frame
> (data3).
>
> I have this code I am confused with:
>
> malMap <- joinCountryData2Map(dF = "data3", joinCode = "ISO3",
> nameJoinColumn = "country")
>
> # This will join your malDF data.frame to the country map data
>
> mapCountryData(malMap, nameColumnToPlot="hdi", catMethod =
> "categorical", missingCountryCol = gray(.8))
>
> head(data3)
>
> country   hdi
>              0
>              0
>              0
>  ASM     0.827
>              0
>              0
>
> Firstly I get this error as it won't match the country names up:
>
> "Error in joinCountryData2Map(dF = "data3", joinCode = "ISO3",
> nameJoinColumn = "country") :  your chosen nameJoinColumn :'country'
> seems not to exist in your data, columns ="
>
> How can I change this sample code to colour the three levels of hdi?
> Is it possible with this code? Also, is it possible to manually make
> the small island nations bigger as they will not appear at this scale.
>
> I'm sorry this is so long. Any help would be greatly appreciated.
>
> Cheers,
>
> Sarah
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list