Southern Africa (South Africa, Lesotho, Swaziland, Namibia, Botswana, Zimbabwe and Mozambique south of the Zambezi) has a pretty rich diversity of birds. My third edition “Sasol Birds of Southern Africa” reports 951 species occurring in the region, 144 of which are endemics or breeding endemics. To put things into perspective, that’s more birds than there are in Canada and the USA combined! Given this plethora of birds, there have been surprisingly few phylogeographic studies conducted on them¹, especially considering the long history of avian research in the region.

Perhaps even more surprising is that among the small collection of phylogeographic work on our birds, not a single study has focussed on species occurring largely or only within the Cape Floristic Region (CFR), a global biodiversity hotspot2,3. The Percy FitzPatrick Institute of African Ornithology (PFIAO or Fitztitute) has been around for more than 50 years and, situated as it is at the University of Cape Town in the “heart” of the CFR, it really is a wonder that nobody has yet explored the phylogeography of any CFR-endemic birds. I’m not complaining though, since exploring the phylogeography of a fynbos endemic bird/s is exactly what I’ll be doing for my M.Sc.. It would be a lot less exciting, I think, if somebody had done it all before.

My work will focus on the two CFR-endemic nectarivores, Cape Sugarbird (Promerops cafer) and Orange-breasted Sunbird (Anthobaphes violacea). As with the remaining four CFR-endemic passerines, these birds are pretty much restricted to fynbos, the dominant vegetation type within the CFR4. The primary objective of my study is to examine the spatial distribution of genetic diversity in my two focal species. Given that both are thought to be pretty poor dispersers (not so clear in the sugarbirds…) and given the somewhat insular and dynamic distribution of their fire-prone habitat, we expect to find strong patterns of divergence between populations, a.k.a genetic structure.

The first requirement for showing this is a sampling scheme that covers the entire range of the species you’re interested in and samples across any potential barriers to dispersal/gene flow. This is where maps come in, allowing you to visualise your sampling scheme by plotting your sampling locations onto the range of your species. I’ve already been on a little field trip, so thought I’d generate a map to assess my coverage and highlight areas to target on future trips. To do this, I turned to “R“. R is a language and software for statistical computing. As a geographic information system (GIS), it is just as capable as more popular GIS software packages such as ArcGIS or QGIS. Lovelace & Cheshire (2015) provide a very good introduction to R as a GIS. Also, Jasper Slingsby from SAEON gave a talk on handling spatial data in R to the Cape R user group last year. The talk was recorded and the materials have been posted on RPubs.

Before looking at the final product, let’s take a look at the code I used to generate my maps. We’ll deal with Cape Sugarbird only, since the coverage for them is a little better than Orange-breasted Sunbird. Note that the code is not self-contained. You’ll be able to download the country borders through R, but the point localities are from a .csv file on my computer and the vegetation polygons were downloaded from SANBI.

The first step is to ensure that you have installed and loaded the packages necessary for working with spatial data:

# Loading and installing packages -----------------------------------------
x <- c("ggmap", "rgdal", "rgeos", "maptools", "dplyr", "tmap",
        "raster", "rJava","ggplot2", "sp")
lapply(x, library, character.only = TRUE)


Then, load the spatial data. The South African borders are obtained from GADM using the “getDATA” function in the raster library. The argument “level=1” downloads the map with provincial subdivisions, and you can adjust the value for finer divisions (e.g. municipalities) or no divisions. You’ll also need to manipulate the data a bit to get it into shape for mapping. This includes setting identical Coordinate Reference Systems (CRS) for any spatial objects and subsetting the the dataframe with all the localities to include only latitude and longitude (all we need to plot the points on a map).

# Loading spatial data ----------------------------------------------------
ZA_border <- getData("GADM", country = "ZAF", level = 1)

#Make an object with standard CRS for later use
stdCRS <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
#reproject map
ZA_border <- spTransform(ZA_border, CRSobj=stdCRS)

#read in locality data
CSB_loc <- read.csv("G:\\UCT\\2016\\MSc\\Maps\\Coverage map\\data\\CSB_localities.csv", sep=";")
CSB_loc <- subset(CSB_loc, select=c(lat,lon)) #select only lat, lon
coordinates(CSB_loc) <- ~lat+lon 
proj4string(CSB_loc) <- stdCRS
spTransform(CSB_loc, CRSobj=stdCRS)
CSB_loc_df<-read.csv("G:\\UCT\\2016\\MSc\\Maps\\Coverage map\\data\\CSB_localities.csv", sep=";")
CSB_loc_df <- subset(CSB_loc_df, select=c(lat,lon))
#read in biomes 
biomes <- readOGR(dsn="G:\\UCT\\2016\\MSc\\Maps\\Coverage map\\data\\biomes",layer="vegm2006_biomes_withforests")
proj4string(biomes) <- stdCRS
spTransform(biomes, CRSobj=stdCRS)
identicalCRS(biomes, ZA_border) #Check CRS's match!



The last line of the above code plots the polygons for the map of South Africa. This results in the plot below:


Map of South Africa with provincial boundaries.


“CSB_loc” is a SpatialPoints object containing the coordinates of all our sampling sites. Let’s plot those on the map! While we’re at it, let’s also plot the “fynbos biome” by subsetting the biomes SpatialPolygons object. Also, sugarbirds are restricted to fynbos vegetation in the southwestern corner of South Africa, so there’s not much point in plotting the whole country each time. We’ll crop the plotting area to accommodate only the fynbos (and a little extra).

#Crop the SA border to extent of fynbos
ZA_border_crop <- crop(ZA_border, extent(biomes[biomes$BIOMENAME=="Fynbos",])*1.10)
#Plot the points and biome onto the map
points(CSB_loc, pch=21, bg="pink",cex=1.5,col="black")



Our first attempt at a coverage map! Looks okay, eh? Excuse my awful colour choices.

Alright, so the map we produced using R’s base plotting looks okay. I’m sure there are a bunch of tricks you could use to get it looking really nice using base plotting, but I really just prefer using ggplot2 for just about all my plotting needs, maps included. Te problem though is that ggplot2 doesn’t handle spatial objects, so you have to convert all of these to data frames, often losing some information along the way. This information can always be appended to the data frames later though.

The first step is to create a theme with many of the default background elements removed (such as gridlines, axes etc). I got hold of this function from Winston Chang’s “R Graphics Cookbook5“, which is a really fantastic resource if you’re keen to start plotting using ggplot2 :

# GGplot map --------------------------------------------------------------
# Create a theme with many of the background elements removed 
theme_clean <- function(base_size = 12) {
  require(grid) # Needed for unit() function 
  theme_grey(base_size) %+replace%
      = element_blank(),
      = element_blank(),
      panel.background = element_blank(), panel.grid
      = element_blank(),
      axis.ticks.length = unit(0, "cm"), axis.ticks.margin = unit(0, "cm"), panel.margin
      = unit(0, "lines"),
      = unit(c(0, 0, 0, 0), "lines"), complete = TRUE ) }


Then, all we need to do is convert our spatial objects to data frames using fortify(), and we’re ready to plot:

CSB<-ggplot(ZA_border_f, aes(x=long,y=lat,group=group))+
  geom_polygon(data=biomes_f_fynbos,aes(x=long,y=lat,group=group,fill="grey"),alpha = 0.8)+


This gives the following map, which I hope you’ll agree looks a little better than the one produced using base plotting:

ggplot_mapI certainly think it looks better. Unfortunately, the green polygon I end up plotting is still the “fynbos biome” which includes the lowland renosterveld vegetation. I’m still working on subsetting the biomes polygon to contain only vegetation types suitable for sugarbirds which will give a better idea of how well we’re sampling their potential range. In this regard, I’ve had some other ideas including plotting the points onto data from the Protea Atlas Project or a MaxEnt SDM of the sugarbird’s range. Watch this space.

Anyway, beyond sampling throughout the sugarbird’s range, the number of individuals sampled at each site is also important. More individuals means more power to detect genetic differences both between and among populations. To show this on a map, you could simply annotate each point on your map with the sample size for that locality. I think that’s a little messy though. Having them in a separate table is a little boring too. So, I turned to the package “leaflet” which lets you create interactive (i.e. “clicky-clicky-draggy-draggy zoom”) maps using the Leaflet JavaScript library. Unfortunately, you have to save these maps as .html files, which aren’t supported on I can, however, show you a few still images of the maps to give you an idea of what they look like, and the code I use to generate them:

# Attempted interactive map -----------------------------------------------
#Loading the leaflet package
#Reading in the locality and sample size data
CSB_loc_leaflet<-read.csv("G:\\UCT\\2016\\MSc\\Maps\\Coverage map\\data\\CSB_localities.csv", sep=";")
coordinates(CSB_loc_leaflet) <- ~lat+lon 
proj4string(CSB_loc_leaflet) <- stdCRS
spTransform(CSB_loc_leaflet, CRSobj=stdCRS)
#Generating locality name and sample size data for popups
CSBcontent <- paste(sep = "<br/>",
#CSB maps
leaflet() %>%
  addProviderTiles("Esri.WorldImagery") %>%
             clusterOptions = markerClusterOptions()) 
leaflet() %>%
  addProviderTiles("Esri.WorldTopoMap") %>%
             clusterOptions = markerClusterOptions())



The maps are composed of .png tiles from various “providers”. Here, I’ve used the “Esri.WorldImagery” tiles, which I think are awesome. There are a whole bunch of options though (see here). The site markers (blue “teardrops) can be clicked to bring up a popup with the site name and the number of individuals sampled there. The site markers are aggregated into clusters depending on zoom. Besides being pretty neat, I guess that the clustering is a useful way of getting a general idea of your coverage when zoomed out. Take the first image above as an example. It shows that we are doing pretty well in sampling sugarbirds in the east of their range. The west, however is pretty thin at the moment, with only one site with three birds in the northern cederberg and nothing at all on the Cape Peninsula, where I live.

This was my first time grappling with spatial data in R and although mapping points is really a simple excercise, I found that it was a pretty useful way to familiarise myself with the basics of spatial data. I’m looking forward to trying more complex problems in the future. For example, I’d like to use MaxEnt species distribution models in R to project the sugarbirds climatic niche at thousand-year intervals back into the past to identify areas of potential stability/instability (refugia, I guess).



¹Tolley, K. a et al., 2014. The shifting landscape of genes since the Pliocene: terrestrial phylogeography in the Greater Cape Floristic Region. In N. Alsopp, J. F. Colville, & G. A. Verboom, eds. Fynbos: Ecology, Evolution and Conservation of a Megadiverse Region. Oxford, UK: Oxford University Press, pp. 142–163.

²Mittermeier, R. et al., 1999. Hotspots: Earth’s biologically richest and most endangered terrestrial ecoregions., Conservation International.

³Myers, N. et al., 2000. Biodiversity hotspots for conservation priorities. Nature, 403(6772), pp.853–858.

4Bergh, N.G. et al., 2014. Vegetation types of the Greater Cape Floristic Region. In N. Alsopp, J. F. Colville, & G. A. Verboom, eds. Fynbos: Ecology, Evolution and Conservation of a Megadiverse Region. Oxford, UK: Oxford University Press, pp. 1–25.

5Chang, W., 2012. R graphics cookbook M. Loukides & C. Nash, eds., Sebastopol: O’Reilly Media.



One thought on “Maps!

  1. Pingback: Representing bird atlas data (SABAP2) on a map | sugarbirds 'n stuff

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s