Home  /  Guides  /  Working with your data

Viewing datasets from the ACE Database

ACER is the R script and documentation for managing data in the ACE Database through R Studio.

Viewing a dataset that includes geojson shapes

Click on acer_dataset_request in the documentation to see instructions. This is the script for viewing datasets in the ACE database. An example script is shown below, and runs through the following steps:

  1. Ensure you have all the relevant libraries installed
  2. Authenticate and connect (acer_connect("host", "site", user, token))
  3. Request the dataset (acer_dataset_request("name of the dataset", f = "output format" (which can be either “json”, “geojson” or “csv”))
  4. Read & parse the dataset, and check for validity – in the example below, the dataset is being read into a variable called transects, any invalid shapes are being ignored, and the validity of the geojson is being checked
  5. Use tmap to create a view of the transects – in the examples below, we (a) Create variables for birds of interest, and (b) Use tmap commands to create lines of different colors for the birds of interest
  6. Create the map

Example script

This script would enable viewing of the BBS data as a map, with transects containing skylarks, yellowhammers and buzzard shown in different colors.

# R script to display a map of the BBS transects, showing the sections on which
# skylarks, yellowhammers and buzzards were recorded.
library(jsonlite)
library(httr)
library(sf)
library(dplyr)
library(tmap)
library(acer)
# Connect to the ACE server.
rsp <- acer_connect(host, site, user_email, user_token)
# Build a URL to request the BBS dataset. By default the output from acer_dataset_request
# is JSON, but by requesting geojson, each data point is a drawable shape with properties.
request <- acer_dataset_request("BBS2", f = "geojson")
# Read the dataset and parse the geojson received. If you look at transects in R Studio,
# you will see each of the BBS records.
transects <- st_read(request)
# If there is an invalid shape, ignore it
tmap_options(check.and.fix = TRUE)
# Ensure the transects data is valid geojson.
st_is_valid(transects)
# Use tmap to create a view of the transects.
tmap_mode(mode = "view")
# Extract the data for the species we are interested in.
buzzards <- filter(transects, CommonName == "Buzzard")
skylarks <- filter(transects, CommonName == "Skylark")
yellowhammers <- filter(transects, CommonName == "Yellowhammer")
# Create a map using Leaflet/OpenStreetMap.
#
# Draw each transect in grey, and then mark the sections in which each of our species appear;
# show skylarks in blue, yellowhammers in yellow and buzzards in red.
map1 <- tm_basemap(leaflet::providers$CartoDB.Voyager)+tm_shape(transects)+tm_lines(col="grey", lwd=5)+
tm_shape(skylarks)+tm_lines(col="blue")+
tm_shape(yellowhammers)+tm_lines(col="yellow", lwd=3)+
tm_shape(buzzards)+tm_lines(col="red", lwd=1)
# Display the map
print(map1)

Questions or problems?

Get in touch and we'll help you get set up.

Contact ACE Nature