Distribution maps in R

Today i’m gonna play a little bit with map features and show you how to make different basic distribution maps in R. Using the 2.14.1 Version of R i will make a graphical distribution map of the dragonflies species in Bavaria. The data was extracted from the book “Libellen in Bayern” and applied to a presence-absence matrix. The whole of bavaria was converted to a geographical grid (X,Y-Values), whose values came from available topographical maps. Iam open to any suggestions or other packages which could present such data in a fashionable way!

For basic great looking maps you could use the package sp and lattice. Also i suggest using the package RColorBrewer, which provides very nice color ranges. See the comments in the R-Code for explantations.

library(sp);library(lattice)   # Loads all libraries
data <- read.csv2("grid_bayern.csv",
header=T,dec=",",sep=";",na.strings="NA") # Load the data
### The date has the following columns: "X","Y","Diversity"
coordinates(data) <- c("X","Y") # Apply X-Y Values as coordinates to form a SpatialPointsDataFrame.
## coloured points plot with legend in plotting area and scales
spplot(data, "Diversity",
cuts = 3, col.regions=brewer.pal(3, "Set1")[3:1],
legendEntries = c("small","avarage","high"))

## Blubble Plot --> Increasing bubble size for higher values
bubble(data, "Diversity", maxsize = 1.5,pch=19,
main = "Bavaria Dragonfly diversity", key.entries = c(1,5,10,25,50),scales=list(draw=F))

Diversity for bavarian dragonfliesBubbleplot for bavarian dragonlies

As some points seem to be missing you could also build an interpolated graphic. For this first we will need the packages maps, akima and fields. The code below loads in the dataset and defines our X and Y-Axis ranges and interpolates all data to adjacent areas based on contour-lines. Please note that these distribution is just a default kriging, which doesn’t have to be right. You need to look to some variograms and adjust your map to build the correct interpolated values.

library(akima);library(fields) ## Load all libraries
data <- read.csv2("grid_bavaria.csv",header=T,
dec=",",sep=";",na.strings="NA") ## load the data
rx=range(data$X);ry=range(data$Y) ## define the ranges of the plots

int.scp <- interp(data$X,data$Y), data$diversity, duplicate="strip") ## Make an interpolation

# Build the image plot with the interpolated values
col=brewer.pal(10, "Spectral")[10:1],nlevel=10,main="Spatial Diversity")
#contour(int.scp,add=TRUE) # You could also show the contour lines with this command

Interpolated dragonfly diversity for bavaria


Tags: , , ,

About Martin Jung

PhD researcher at the University of Sussex. Interested in nature conservation, ecology and biodiversity as well as statistics, GIS and 'big data'
Sussex Research Hive

Supporting the research community at the University of Sussex

Small Pond Science

Research, teaching, and mentorship in the sciences

Landscape Ecology 2.0

intersecting landscape ecology, open science, and R


The Research Blog of IIASA

Jörg Steinkamps Blog

Mainly things about R, Linux and vegetation modeling

Amy Whitehead's Research

the ecological musings of a conservation biologist

Michael McCarthy's Research

School of BioSciences, The University of Melbourne

The Rostrum

science, statistics, policy and more


Environmental Change - Understand, Predict, Adapt

Dynamic Ecology

Multa novit vulpes


METeorological Visualisation Utilities using R for Science and Teaching

A Birder´s Blog

"Everybody loves what they know"


A new metric to quantify biodiversity response to fragmentation

Trust Me, I'm a Geographer

Using Technology to Explore Our World

Duncan Golicher's weblog

Research, scripts and life in Chiapas

%d bloggers like this: