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", scales=list(draw=F),key.space=list(x=0.73,y=0.9,corner=c(0,1)), 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))
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(RColorBrewer);library(maps); 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 image.plot(int.scp,xlim=rx,ylim=ry,legend.shrink=0.7, 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