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

MacQueen, Don macqueen1 at llnl.gov
Wed Aug 28 19:19:45 CEST 2013


Rhona,

I am completely unfamiliar with the package and functions you're using,
so I had supposed you would use functions from the sp and rgdal packages.
For what it's worth, I'll give an example below.

However, probably you will need to share at least a representative portion
of your data in order for people to give useful help. One way is to
include the ouput of the dput() function. In your case, probably,
  dput(data3)
or perhaps
  dput(head(data3))
if data3 is big.


Here is an example that requires that your countries be stored in a
SpatialPolygonsDataFrame. In this example, first we create some arbitrary
polygons, then plot them. It's not complete solution for your situation,
but is, I hope, analogous.

Probably, my email software will mangle the line lengths.

## example data, creating a SpatialPolygonsDataFrame
## copied from help('over',package='sp')
r1 = cbind(c(180114, 180553, 181127, 181477, 181294, 181007, 180409,
 c(332349, 332057, 332342, 333250, 333558, 333676,   180162, 180114),
                     332618, 332413, 332349))
r2 = cbind(c(180042, 180545, 180553, 180314, 179955, 179142, 179437,
  179524, 179979, 180042), c(332373, 332026, 331426, 330889, 330683,
                             331133, 331623, 332152, 332357, 332373))
r3 = cbind(c(179110, 179907, 180433, 180712, 180752, 180329, 179875,
  179668, 179572, 179269, 178879, 178600, 178544, 179046, 179110),
  c(331086, 330620, 330494, 330265, 330075, 330233, 330336, 330004,
    329783, 329665, 329720, 329933, 330478, 331062, 331086))
r4 = cbind(c(180304, 180403,179632,179420,180304),
  c(332791, 333204, 333635, 333058, 332791))
     
sr1=Polygons(list(Polygon(r1)),"r1")
sr2=Polygons(list(Polygon(r2)),"r2")
sr3=Polygons(list(Polygon(r3)),"r3")
sr4=Polygons(list(Polygon(r4)),"r4")
sr=SpatialPolygons(list(sr1,sr2,sr3,sr4))
srdf=SpatialPolygonsDataFrame(sr, data.frame(cbind(1:4,5:2),
row.names=c("r1","r2","r3","r4")))


## now plot
plot(srdf)
plot(srdf,col=1:4)




-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 8/28/13 8:58 AM, "Rhona Govender" <rhonag at gmail.com> 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
>
>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



More information about the R-sig-Geo mailing list