Skip to contents

This vignette shows you how to use the function map_summary() to visualize important features for each deployment on an interactive leaflet map such as:

  • number of detected species
  • number of events observed
  • number of observations
  • number of individuals observed
  • RAI (Relative Abundance Index) (calculated based on observations or individuals)
  • effort (duration of a deployment)

Setup

Load the packages that will be used in this example:

library(camtraptor)
#> 
#> Attaching package: 'camtraptor'
#> The following object is masked from 'package:base':
#> 
#>     contributors
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

For this example the function example_dataset() is used to load an example Camera Trap Data Package dataset. The dataset is derived from a study on detecting invasive muskrat and coypu populations using camera traps.

Before making a visualization with map_summary(), the Camera Trap Data Package dataset should be transformed to a grouped data frame. This can be done by using the function summarize_observations() or summarize_deployments(), depending on what aspect of the dataset you want to visualize. Both are demonstrated in this example.

summ_obs <- x %>%
  summarize_observations(group_by = c("deploymentID", "latitude", "longitude"))

summ_depl <- x %>%
  summarize_deployments(group_by = c("deploymentID", "latitude", "longitude"))

Let’s also create a Camera Trap Data Package dataset that is filtered for a specific species.

To do so, you can first inspect which species have been detected. The function taxa() gives you an overview of the unique scientific names within the Camera Trap Data Package dataset:

taxa(x)
#> # A tibble: 10 × 5
#>    scientificName     taxonID  taxonRank vernacularNames.eng vernacularNames.nld
#>    <chr>              <chr>    <chr>     <chr>               <chr>              
#>  1 Anas platyrhynchos https:/… species   mallard             wilde eend         
#>  2 Anas strepera      https:/… species   gadwall             krakeend           
#>  3 Ardea              https:/… genus     great herons        reigers            
#>  4 Ardea cinerea      https:/… species   grey heron          blauwe reiger      
#>  5 Aves               https:/… class     bird sp.            vogel              
#>  6 Homo sapiens       https:/… species   human               mens               
#>  7 Martes foina       https:/… species   beech marten        steenmarter        
#>  8 Mustela putorius   https:/… species   European polecat    bunzing            
#>  9 Rattus norvegicus  https:/… species   brown rat           bruine rat         
#> 10 Vulpes vulpes      https:/… species   red fox             vos

This example filters for Anas platyrhynchos. You can filter by using the filter_observations() function:

x_anas_p <- x %>% 
  filter_observations(scientificName == "Anas platyrhynchos")

summ_obs_anas_p <- x_anas_p %>%
  summarize_observations(group_by = c("deploymentID", "latitude", "longitude"))

Create maps

Basic usage

Number of detected species

You can visualize the number of detected species by each deployment by using the function map_summary() with feature set to n_scientificName:

 summ_obs %>%
  map_summary(feature = "n_scientificName")

Number of events observed

To visualize the number of events observed, set feature = n_events:

summ_obs %>%
  map_summary(feature = "n_events")

Number of observations

To visualize the number of observations, set feature = n_observations:

summ_obs %>%
  map_summary(feature = "n_observations")

You can also visualize the number of observations for a specific species:

summ_obs_anas_p %>%
  map_summary(feature = "n_observations")

When the argument extend is set as TRUE within the summarize_observations() function, the deployments without observations for Anas platyrhynchos will also be visualized by a black multiplication symbol ×:

# Make grouped data frame by summarizing
summ_obs_anas_p_extend <- x_anas_p %>%
  summarize_observations(
    group_by = c("deploymentID", "latitude", "longitude"), 
    extend = TRUE
  )

# Visualize
summ_obs_anas_p_extend %>%
  map_summary(feature = "n_observations")

Number of individuals

To visualize the number of observed individuals, set feature = sum_count:

summ_obs %>%
  map_summary(feature = "sum_count")

As for observations, you can also visualize the number of observed individuals for a specific species:

summ_obs_anas_p %>%
  map_summary(feature = "sum_count")

RAI (observations)

Note: Notice that in this package the RAI is normalized over a deployment activity period of 100 days.

To visualize the Relative Abundance Index (RAI) for a given species (e.g. Anas platyrhynchos), set feature = "rai_observations". This RAI is based on the number of observations, see the next section on how to calculate the RAI on the number of detected individuals.

summ_obs_anas_p %>%
  map_summary(feature = "rai_observations")

RAI (individuals)

Note: Notice that in this package the RAI is normalized over a deployment activity period of 100 days.

You can also visualize the RAI based on the number of detected individuals instead of the number of observations (see previous section). Set feature = "rai_count":

summ_obs_anas_p %>%
  map_summary(feature = "rai_count")

Effort

You can visualize the duration of the deployments, also called effort, as number of active hours by using the grouped data frame created by summarize_deployments() in the section ‘Setup’. Set feature = "effort_duration":

summ_depl %>%
  map_summary(feature = "effort_duration")

Other units than ‘hour’ (which is the default) can also be used, by using the argument effort_unit. For example, you can express the effort in days:

summ_depl %>%
  map_summary(feature = "effort_duration", effort_unit = "day")

Visualize deployments without detected animals

It can happen that some deployments didn’t detect any recognizable animal (scientificName = NA) or didn’t observe anything at all (deployments with no observations). While visualizing the number of species, these two situations are shown by default as black and red multiplication symbols × respectively:

# Create a data package demonstrating two scenarios:
# 1. Deployments with observations of unknown species (black ×)
# 2. Deployments with no observations at all (red ×)

# Keep only observations with unknown species
x_unknown <- x %>%
  filter_observations(is.na(scientificName))

# Remove all observations from deployment "00a2c20d"
# to simulate a deployment with no observations at all
x_unknown <- x_unknown %>%
  filter_observations(deploymentID != "00a2c20d")

# Summarize, extend = TRUE ensures deployments with no observations are included
summary_obs_unknown <- x_unknown %>%
  summarize_observations(
    group_by = c("deploymentID", "latitude", "longitude"),
    extend = TRUE
  )

# Visualize
summary_obs_unknown %>%
  map_summary(feature = "n_scientificName")

To hide deployments with unknown species or deployments with no observations, set na_values_show or zero_values_show to FALSE respectively.

Clustering and hovering

You can control which variables are displayed when hovering over a deployment using the hover_columns argument. You can choose among all columns from the grouped data frame created with summarize_observations() or summarize_deployments().

In the example below only the deploymentID and the number of observations are shown while hovering:

summ_obs %>%
  map_summary(
    feature  = "n_observations",
    hover_columns = c("deploymentID", "n_observations")
  )

Deactivating both cluster mode and hovering is also possible:

summ_obs %>% 
  map_summary(feature = "n_observations", cluster = FALSE, hover_columns = NULL)

Styling

Use a color palette

The default color palette is a viridis color palette called "inferno". You can specify another viridis color palette, e.g. "viridis" or "magma", or a RColorBrewer palette, e.g. "BuPu" or "Oranges". Below the viridis color palette is used:

summ_obs %>% 
  map_summary(feature = "n_observations", palette = "viridis")

You can use a palette from RColorBrewer, e.g. the "BuPu" palette:

summ_obs %>% 
  map_summary(feature = "n_observations", palette = "BuPu")

Another easy way to specify a palette is to create it by passing a vector of colors as names or hex color codes, e.g. c("black", "blue", "#A3675F"):

summ_obs %>% 
  map_summary(
    feature = "n_observations",
    palette = c("black", "blue", "#A3675F")
  )

Use a specific icon and color for zero values

You can customize the icon shown for zero-value deployments by passing an icon URL to zero_values_icon_url and its size in pixels to zero_values_icon_size. Many free icon libraries are available online, such as icons8. The following example uses a custom icon with a size of 50 pixels:

x_anas_p %>%
  summarize_observations(
    group_by = c("deploymentID", "latitude", "longitude"),
    extend = TRUE
  ) %>%
  map_summary(
    feature = "n_observations",
    zero_values_icon_url = "https://img.icons8.com/color/48/000000/futurama-fry.png",
    zero_values_icon_size = 50
  )

Typically the colour is part of the URL. Here below is an example where you change the color of the default icon to green (2ECC71):

x_anas_p %>%
  summarize_observations(
    group_by = c("deploymentID", "latitude", "longitude"),
    extend = TRUE
  ) %>%
  map_summary(
    feature = "n_observations",
    zero_values_icon_url = "https://img.icons8.com/ios-glyphs/30/2ECC71/multiply.png"
  )

Modifying the default value ("black") can be useful as the color of deployments with zero values can be sometimes too similar to one of the colors used in the palette.

Modify circle size

You can also modify the upper and lower limit of the circle sizes by specifying radius_range (default:c(10,50)):

summ_obs %>% 
  map_summary(feature = "n_observations", radius_range = c(20, 150))

Use absolute scale

By default the upper limit of the color palette and radius are defined based on the actual feature values. However, sometimes it can be useful to set up an absolute upper limit. This can be done by setting argument relative_scale to FALSE and specifying the upper limit in max_scale.

Upper limit lower than number of observations:

summ_obs %>% 
  map_summary(
    feature = "n_observations",
    relative_scale = FALSE,
    max_scale = 2
  )

Upper limit higher than number of observations:

summ_obs %>% 
  map_summary(
    feature = "n_observations",
    relative_scale = FALSE,
    max_scale = 50
  )