[R] mapping data to a geographic map of Europe

paladini at trustindata.de paladini at trustindata.de
Wed Oct 30 17:04:58 CET 2013


Hi Jim,
thats the second time that you helped  me in a short while so thanks a lot!

But it seems to me quite laborious  and error-prone to first select  
all the relevant countries in this long list and then to create a  
color  vector.
But perhaps I get it all wrong.


For the color vector I first did this

imagecolors<-color.scale(mydata$GPIndex ,c(1,0,0),0,c(0,0,1))

because I wanted the colors to scale from dark red (bad ones) to dark  
blue (good ones).
But it went somehow wrong. By the way can you tell me what I did wrong?

Nevertheless I than createt a color vector looking loke this:

eurocol=c("#FF0000FF",8,"#710000FF","#390000FF",8,8,"#390000FF",rep(8,10),"#2F0000FF"
,8,"#000000FF",8,"#000000FF","#000000FF" ,"#000055FF",8,"#000064FF",2,  
"#000083FF",8,8,"#00008BFF" ,"#0000F0FF" ,rep(8,20),"#0000F7FF"  
,rep(8,18),"#0000FFFF", rep(8,120))


And than

  world.map<-map('world', fill = TRUE,col =eurocol  
,xlim=c(-12,35),ylim=c(37,70))

Beside the wrong colors it worked okay.
But I am not really happy with this solution.

Did I misapprehend you?


Best regards and thanks again

Claudi



Zitat von Jim Lemon <jim at bitwrit.com.au>:

> On 10/30/2013 04:02 AM, paladini at trustindata.de wrote:
>> Hello,
>> I would like to draw a map of Europe. Each country should be colored
>> depending on how it scores in an index called GPIndex.
>> Say a dark red for real bad countries a light red for those which are
>> not so bad, light blue for the fairly good ones and so on up to the
>> really good ones in a dark blue.
>> I never worked with geographic maps before so I tried library maps but I
>> didn't get far,- especially because all examples I found only seem to
>> work for the United states. So I'm a bit lost.
>> I would be nice if somebody could help me.
>>
> Hi Claudia,
> If you draw a map of Europe something like this:
>
> world.map<-map('world', fill = TRUE,
>  col = 1:10,xlim=c(-15,40),ylim=c(37,70))
>
> you have a "col" argument that you can pass the colors you want.  
> What you must do is look at the "names" component of "world.map":
>
> $names
>   [1] "Denmark"
>   [2] "USSR"
>   [3] "Italy"
>   [4] "Netherlands"
>   [5] "Iraq"
> ...
>
> to get the indices of the countries. Say Denmark was fairly good,  
> USSR was fairly bad, and so on. You could then pass colors like this:
>
> col=c("lightblue","lightred",...)
>
> in the call to map for as many countries as you wanted. Pass NA for  
> those countries that you don't want to color.
>
> Jim



More information about the R-help mailing list