Introduction

Although the zoomable maps produced by mapview provide the most powerful tools for investigating the data yourself, there will usally come a point when you are wrting up an analysis when you need to produce maps as figure that can be placed in the article. It can be very challenging to show complex spatial information in a clear and communicable manner. Maps tend to become very “busy” and it is quite easy to lose their context.

Showing where the study site is

A map that helps the reader to locate the study site is usually a good first step. This can be placed in the methods section, rather than the results.

library(tidyverse)
library(mapview)
library(sf)
library(tmap)
library(RColorBrewer)
library(rnaturalearth)
load("Exploratory_maps.rda")

The rnaturalearth package holds some rather low resolution outline maps of countries and administrative regions (in the case of the UK these are counties). These can be useful as a simple base when plotting the spatial data.

We can get the UK counties with this line of code. Notice the use of st_transform. The data are provided with coordinates as latitude and longitude. But we are working with data in the British National grid coordinate reference system. This is EPSG code 27700. So the data are reprojected into this CRS.

ne_states(country="United Kingdom", return="sf") %>% st_transform(crs=27700)-> UK

We might just want a subset of counties. To get this you can use a filter that looks for matches in a lost of names. The names have to be precisely the same as those in the data.

UK %>% filter(name %in% c("Dorset","Hampshire", "Isle of Wight")) -> South

To help the reader locate the study are we might start with a map showing where the southern counties lie in the UK.

tmap_style("natural")
qtm(UK, style ="natural", title="UK") +qtm(South,fill="red") ->ukmap
ukmap

We could then add the habitat (land use) map to just the southern counties.

tmap_style("classic")
qtm(South) +qtm(habitat,legend=FALSE, title="Land use") ->hmap
hmap

To give an impression of the number of point observations of all bird species we could combine the counties with the bird data.

qtm(South) +qtm(birds,legend=FALSE, title="bird observations") ->bmap
bmap

Or do this just for one species. Note the use a filter to select the species.

qtm(South) +qtm(filter(birds,Species=="Yellowhammer"),legend=FALSE, title="Yellowhammer observations") ->yhmap

Arranging the maps to produce a figure.

The four maps produced by the code above can be placed together as a single figure using the tm_arrange function.

tmap_arrange(ukmap,hmap,bmap,yhmap, asp=NA, ncol=2) -> fig1
fig1
Figure 1. Study area in Dorset and Hampshire

Figure 1. Study area in Dorset and Hampshire

Showing a single species over the land cover map

tmap_style("classic")
qtm(habitat, fill="LandCover")  +qtm(filter(birds,Species=="Yellowhammer"), title ="Yellowhammer", fill="red") + tm_scale_bar()  ->yh
yh

save(list=ls(),file="Printable_maps.rda")