Occurence data
Importing occurrence data
The package dismo provide a function to direct download occurrence data from GBIF. We will use this function to download the occurrence data of the rose-ringed parakeet (Psittacula krameri)
> library(dismo)
> krameri<-gbif(genus="Psittacula", species="krameri", geo=T, concept=T)
The arguments geo=T tell to the function to download only those records provided with latitude and longitude. The arguments concept=T tells to the function to download also the data from subspecies.
Now we check which kind of information we downloaded:
> colnames(krameri)
| [1] | "species" | "continent" | "country" | "adm1" |
| [5] | "adm2" | "locality" | "lat" | "lon" |
| [9] | "coordUncertaintyM" | "alt" | "institution" | "collection" |
| [13] | "catalogNumber" | "basisOfRecord" | "collector" | "earliestDateCollected" |
| [17] | "latestDateCollected" | "gbifNotes" | "downloadDate" | "maxElevationM" |
| [21] | "minElevationM" | "maxDepthM" | "minDepthM" | "ISO2" |
| [25] | "cloc" |
There are 25 variables. We are interested in latitude (lat), longitude (lon) and uncertainity associated to coordinates (coordUncertaintyM). Just for our convenience we will discard other information:
> krameri<-krameri[,c(7:9)]
Now we have the data, composed by three variables, necessary to start. First of all we want check the composition of the dataset with the R functions head(), summary() and str():
> head(krameri)
| lat | lon | coordUncertaintyM | |
| 1 | -20.083300 | 57.58330 | <NA> |
| 2 | -20.083300 | 57.58330 | <NA> |
| 3 | -20.450000 | 57.66670 | <NA> |
| 4 | -20.083300 | 57.58330 | <NA> |
| 5 | 19.766666 | 85.33336 | <NA> |
| 6 | 9.511201 | 76.35395 | <NA> |
> summary(krameri$lat)
| Min. | 1st Qu. | Median | Mean | 3rd Qu. | Max. | NA's |
| -37.92 | 24.55 | 28.53 | 33.19 | 51.38 | 60.40 | 7 |
> str(krameri)
'data.frame' : 8078 obs. of 3 variables:
$ lat: num -20.1 -20.1 -20.4 -20.1 19.8 ...
$ lon: num 57.6 57.6 57.7 57.6 85.3 ...
$ coordUncertaintyM: chr NA NA NA NA ...
From the inspection of the dataset emerge that there are some missing coordinates (NAs) and that the coordinates uncertainty was loaded as character vector instead that numeric vector. We change "coordUncertaintyM" from character to numeric:
> krameri$coordUncertaintyM <-as.numeric(krameri$coordUncertaintyM)