paladini at trustindata.de
2013-Oct-29 17:02 UTC
[R] mapping data to a geographic map of Europe
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. Thanking you in anticipation! Best regards Claudia
Check out this link for some examples http://www.r-bloggers.com/maps-in-r-choropleth-maps/ Jean On Tue, Oct 29, 2013 at 12:02 PM, <paladini@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. > > Thanking you in anticipation! > > Best regards > > Claudia > > ______________________________**________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
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
Claudia, You should cc r-help on all correspondence so that others can follow the thread. In the second paragraph of the link I sent you http://www.r-bloggers.com/maps-in-r-choropleth-maps/ a link is provided for the NUTS data, "The polygons for drawing the administrative boundaries were obtained from this link. In particular, the NUTS 2010 shapefile in the 1:60 million scale was downloaded and used. The other available scales would allow the drawing of better defined maps, but at a computational cost. The zipped file has to be extracted in a folder of choice for using it later." http://epp.eurostat.ec.europa.eu/portal/page/portal/gisco_Geographical_information_maps/popups/references/administrative_units_statistical_units_1 If you want to follow the example, you will need to download this data to your computer and then make sure that you refer to the appropriate directory when using the readShapePoly() function. Jean On Wed, Oct 30, 2013 at 11:14 AM, <paladini@trustindata.de> wrote:> Hi Jean, > thank you for your advice. > The page looks quite interesting and I tried the example in GNU R. I did > all the downloads. > But > Just in the beginnig after typing > > eurMap <- readShapePoly(fn="NUTS_2010_**60M_SH/Shape/data/NUTS_RG_60M_** > 2010") > I get the following error message: > > Error in getinfo.shape(filen) : Error opening SHP file > > To you have an idea what I did wrong? > > Thanks a lot and best regards > > Claudia > > > > > Zitat von "Adams, Jean" <jvadams@usgs.gov>: > > Check out this link for some examples >> http://www.r-bloggers.com/**maps-in-r-choropleth-maps/<http://www.r-bloggers.com/maps-in-r-choropleth-maps/> >> >> Jean >> >> >> On Tue, Oct 29, 2013 at 12:02 PM, <paladini@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. >>> >>> Thanking you in anticipation! >>> >>> Best regards >>> >>> Claudia >>> >>> ______________________________****________________ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/****listinfo/r-help<https://stat.ethz.ch/mailman/**listinfo/r-help> >>> <https://stat.**ethz.ch/mailman/listinfo/r-**help<https://stat.ethz.ch/mailman/listinfo/r-help> >>> > >>> PLEASE do read the posting guide http://www.R-project.org/** >>> posting-guide.html <http://www.R-project.org/**posting-guide.html<http://www.R-project.org/posting-guide.html> >>> > >>> >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> > >[[alternative HTML version deleted]]