The Atlas of Living Australia (ALA) has produced a very nice (and fast) package to retrieve species occurrences (and more) from their database. The following short example code shows the use of the main function occurrences, but I recommend you to read on other functionality included (see the vignette: vignette(ALA4R)).
First install the ALA4R package from CRAN.
When using the ALA4R package, you have to specify the reason for downloading records. Please take this seriously, as it helps the ALA to keep track of what the data are being used for. The following command shows the reasons (the id field):
library(ALA4R)
ala_reasons()
## rkey
## 1 logger.download.reason.biosecurity
## 2 logger.download.reason.citizen.science
## 3 logger.download.reason.collection.mgmt
## 4 logger.download.reason.conservation
## 5 logger.download.reason.ecological.research
## 6 logger.download.reason.education
## 7 logger.download.reason.environmental
## 8 logger.download.reason.restoration.remediation
## 9 logger.download.reason.research
## 10 logger.download.reason.systematic.research
## 11 logger.download.reason.other
## 12 logger.download.reason.testing
## name id
## 1 biosecurity management/planning 1
## 2 citizen science 11
## 3 collection management 5
## 4 conservation management/planning 0
## 5 ecological research 7
## 6 education 3
## 7 environmental assessment 2
## 8 restoration/remediation 12
## 9 scientific research 4
## 10 systematic research/taxonomy 8
## 11 other 6
## 12 testing 10
I will here use reason 10 (testing). It can be set as an option that will be reused, or simply pass it as an argument like in the following example (I prefer this for reproducibility reasons).
# Download occurrences like this.
# Will take a few seconds - and is faster the next time as it uses a local cache.
euc <- occurrences("Eucalyptus parramattensis", download_reason=10)
Next I use the oz package to make a simple map of NSW, and plot the occurrences, coloured by whether the point was listed as an ‘outlier’.
library(oz)
oz(sections=c(4,13,14,15))
with(euc$data, points(longitude, latitude, pch=16, col=ifelse(detectedOutlier, "red", "blue")))
Note that to plot NSW, we have to specify each border section separately (see ?oz).
In this example I will show how to use the mapview package to make fancy interactive maps with little effort. The mapview package has many options, and can also plot polygons, lines and other spatial objects. Here I only plot occurrences (points) coloured by some variables (subspecies and detectedOutlier).
library(mapview)
## Loading required package: leaflet
# Needed to set coordinates.
library(raster)
## Loading required package: sp
# Subset of the occurrence data.
# Important is that there are no missing values in lat/long,
# and that you only select those variables you want included in the plot.
eucocc <- subset(euc$data, !is.na(longitude) & !is.na(latitude),
select=c(longitude, latitude, subspecies, detectedOutlier))
# raster-code to set the coordinates of the dataframe, this
# also converts the dataframe to a 'SpatialPointsDataFrame.
# This particular projection is the standard one for latitude
# and longitude data.
coordinates(eucocc) <- ~longitude+latitude
proj4string(eucocc) <- CRS("+proj=longlat +datum=WGS84")
Now we are ready to make the map. This is a zoomable, moveable map. The argument burst=TRUE allows us to select any of the factor variables present in the dataframe to use for colouring (hence my subset above). I have also reduced the size of the plotting symbols (cex=0.3).
mapview(eucocc, cex=0.3, burst=TRUE)