This post is a brief follow-up to a question that appeared some time ago on the “The R Project for Statistical Computing” LinkedIn group, which I’m reporting here:

How can I draw a map of MODERN Europe?

Hi, I'm trying to draw a map of modern Europe but I've found only maps of twenty years ago, with Yugoslavia and Czechoslovakia still united!!!
Does anyone know where I can get a more recent map to be employed with packages such as 'sp' or 'maps'?
Thank you very much!

Two different solutions to the above question will be provided here, using two different R packages.

Solution #1 - ggmap

The package ggmap allows visualizations of spatial data on maps retrieved from Google Maps, OpenStreetMap or other services.

A map of Europe is obtained with just four lines of R code (including the loading of packages.)

1

2

3

4

5

>library(ggmap)

>library(mapproj)

>map<-get_map(location='Europe',zoom=4)

>ggmap(map)

The second line gets the map from Google Maps, unless a different source parameter is specified (for example source = "osm" for retrieving the map from OpenStreetMap.)

The argument location requires the text you would type into Google Maps search box if you were looking to obtain your map online.

The zoom argument requires an integer. Zero would give a map of the whole world, while the max value of 21 returns a map to the building detail. I chose a value of 4 to display Europe after some trial and error process.

The final line is the one actually drawing the map.

Note that the object returned by ggmap is of class ggplot, thus anything you would normally do with a ggplot (like adding geometries) can be done with ggmap.

Solution #2 – rworldmap

The map produced by the ggmap package is a raster. In other words it is just an image placed on the R graphic device. While it serves the purpose of displaying Europe, and would be fine for the display of spatial point patterns, the raster map is not very convenient when one has data aggregated at the country level and wants to show them by color-coding each country.

Package rworldmap is better suited for the task, as it provides maps as spatial polygons.

Again, plotting a map is just a matter of three lines of code, package loading included.

1

2

3

4

>library(rworldmap)

>newmap<-getMap(resolution="low")

>plot(newmap)

The code is very similar to the one of ggmap. The resolution argument is quite self-explanatory and you can see from the resulting map that "low" is actually a more than acceptable resolution.

In this case we got a map of the whole world. By simply tinkering with the xlim and ylim arguments of the plot function we can limit the display to just Europe.

1

2

3

4

5

6

>plot(newmap,

>xlim=c(-20,59),

>ylim=c(35,71),

>asp=1

>)

Admittedly I got the right numbers for the xlim and ylim parameters with some trial and error process this time too.

Would it be possible to retrieve them in a more automated way?

A quick look at geocoding

The geocode function from the ggmap package finds the coordinates of a location using Google Maps. Thus, finding the coordinates of the European most extreme points is as easy as typing the following code:

Hey Max!
Would be super awesome if you could cover maps and mapping for the different NUTS levels! I know you are conversant in this realm as you seem to work for government.
And please check out my article on a mysterious increase of deaths caused by viral hepatitis in Germany 1998. There is a chance that you find this increase also in Italy. I'd like to hear your opinion about it!
Cheers

And even better, and almost just as easy, is to use the vector data from Natural Earth. These are free (license: public domain), detailed, available in various scales, of very high quality and up-to-date. Use the readOGR() function in the rgdal package to load the map data into R.

One very important thing to keep in mind when plotting maps is that you have to use an appropriate projection (and don’t fiddle with the aspect ratio manually). For Europe, use either the equal-area ETRS-LAEA (EPSG 3035) projection or the conformal ETRS-LCC (EPSG 3034) projection. It’s extremely easy to reproject map data in R. Example:

Would you please explain how can I overlap a plot (with color) on the map? I would like to overlay Cincinnati's crime data on the map. The data is structured into cells of of width 0.002x0.002 (lon,lat) and each cell contains number of crimes happened in that place. How can I show it as a heat map (or something similar) while the underlying can still be seen?

Next post has examples of plotting data over the map (including transparency options to have the underlying still visible.)
Hope that one will answer your question, otherwise I'll be happy to provide more help/links.

Can anyone help me that how to create map in R for forest plots. I have 5 ha plot with subplots of 125. Now i want to create map for 5 ha plot but boundary of 125 plots. i have x and y for each tree. How to do it now. Please comment

I would like to draw a map of north Italy and Austria with several sampling points. i am using getData() function for that. Could you tell me please which format of Longitude and Latitude have to have the sampling points?