### R scripts for importing and curating GBIF records ### R. Castilho || CCMAR || 2015-03-15 ### GOALS # 1. Import GBIF records # 2. Map all the points # 3. Curate reference points # 4. Make final map ############ ### CODE ### ############ ####################################### ### STEP 1 PREPARATION STEPS # see xls example file http://rcastilho.pt/BEMO/GBIF_data_example.xlsx # install packages install.packages(c('xlsx', 'maptools', 'graphics')) # load packages library(xlsx) library(maptools) library(graphics) ####################################### ### STEP 2 LOAD SPECIES DATA # set working directory... change this to the directory in which the species' data is stored and where you want to save output setwd("D:/UTILIZADORES/user-en/Desktop/XXX") # load species' records location.data<-read.xlsx("XXX.xlsx",1) codes<-location.data$code y<-location.data$lat x<-location.data$long ####################################### # REMOVING DUPLICATES # which records are duplicates? dups <- !duplicated(location.data[, 2:3]) dups # remove duplicates location.data <- location.data[dups, ] location.data[,1:3] ####################################### # reducing the geographical area to decrease computation time # here are the minimum and maximum lat-long values of the data #HOW TO DO: if max(x)<0, max(x)=max(x)-5 otherwise max(x)=max(x)+5 xmin=min(x)-5 xmax=max(x)+5 ymin=min(y)-5 ymax=max(y)+5 ####################################### # PLOT MAP data(wrld_simpl) plot(wrld_simpl, xlim=c(xmin,xmax), ylim=c(ymin,ymax), axes=TRUE, col="light grey") # plot points points(x, y, col='red', pch=20, cex=0.5) # plot points again to add a border, for better visibility points(x, y, col='black', cex=0.75) # put labels to simplify id of odd data text(x, y, labs = codes, offset=0.5, cex=1) # removing odd points # e.g.1836 location.data =location.data[-1836,] location.data =location.data[-XX,] location.data =location.data[-XX] location.data =location.data[-XX,] location.data =location.data[-XX,] location.data =location.data[-XX,] location.data =location.data[-XX,] location.data =location.data[-XX,] location.data =location.data[-XX,] location.data =location.data[-XX,] location.data =location.data[-XX,] location.data =location.data[-XX,] # repeat map y<-location.data$lat x<-location.data$long xmin=min(x)-5 xmax=max(x)+5 ymin=min(y)-5 ymax=max(y)+5 data(wrld_simpl) plot(wrld_simpl, xlim=c(xmin,xmax), ylim=c(ymin,ymax), axes=TRUE, col="light grey") # plot points points(x, y, col='blue', pch=20, cex=0.5) # plot points again to add a border, for better visibility points(x, y, col='black', cex=0.5)