Portal Rodent Abundance Demo

Hao Ye



This vignette is a basic guide to begin exploring the Portal data. We load in the data (making sure that we’re using the most recent copy from GitHub), and then explore the rodent abundances over time, with a comparison between the “control” and “kangaroo rat exclosure” treatments.

Package Setup

First we load several packages:

Retrieving the Data

Note that this package does not contain the actual Portal data, which resides online in a GitHub repository.

First, we try to load the data. If there isn’t a Portal folder, than load_rodent_data will fall back to downloading the data, as well.

check whether we already have the data. If we don’t have the data, or if the version we have isn’t the most recent, we use the download_observations function to download the latest copy of the data.

portal_data_path <- tempdir() # use a temporary folder to store downloaded data
data_tables <- load_rodent_data(portal_data_path, download_if_missing = TRUE)
#> Warning in load_datafile(file.path("Rodents", "Portal_rodent.csv"), na.strings = "", : Proceeding to download data into specified path/var/folders/vd/jc3_fd0j7yjbg49g693m7yw40000gn/T//Rtmp3TuHzh
ℹ Running gh query
ℹ Running gh query, got 100 records of about 200
Downloading version 2.18.0 of the data...
#> Loading in data version 2.18.0

The load_rodent_data function reads in several tables related to the rodent abundances. We won’t necessarily use all of these tables, but loading this now gives us access later.

#>                Length Class      Mode
#> rodent_data    29     data.frame list
#> species_table  15     data.frame list
#> trapping_table  8     data.frame list
#> newmoons_table  4     data.frame list
#> plots_table     6     data.frame list

Rodent Abundances

The first table that we loaded (data_tables$rodent_data) is a record of whatever was found in the traps, mostly rodents, but also a few other taxa. If we just wanted to get the rodent abundance data, we could use the abundance function, which has default arguments to filter out the non-rodents.

# get rodent abundance by plot
rodent_abundance_by_plot <- abundance(path = portal_data_path, time = "date", level = "plot") 
#> Loading in data version 2.18.0

rodent_abundance <- rodent_abundance_by_plot %>%
  gather(species, abundance, -censusdate, -treatment, -plot) %>%
  count(species, censusdate, wt = abundance) %>%
  rename(abundance = n)
#>    species            censusdate           abundance      
#>  Length:8841        Min.   :1979-09-22   Min.   :  0.000  
#>  Class :character   1st Qu.:1989-04-01   1st Qu.:  0.000  
#>  Mode  :character   Median :1997-12-28   Median :  0.000  
#>                     Mean   :1998-10-14   Mean   :  6.721  
#>                     3rd Qu.:2008-07-26   3rd Qu.:  5.000  
#>                     Max.   :2018-11-10   Max.   :285.000

Let’s convert the data to long format for easier facetting. Also, we want the scientific names instead of the two-letter species codes, so let’s do that matching, too:

join_scientific_name <- function(rodent_abundance, 
                                 species_table = data_tables$species_table)
  return(rodent_abundance %>%
           left_join(select(species_table, "species", "scientificname"), 
                     by = "species") %>%
           rename(scientific_name = scientificname)

rodent_abundance <- join_scientific_name(rodent_abundance)

Figure: abundance over time

Monthly abundance of rodents (all plots)

Monthly abundance of rodents (all plots)

Next Steps

Our next steps would likely be to dig deeper into the rodent abundances for different treatments, but first we want to know what the different treatments look like, so let’s revisit the abundances later.

Plot Treatments

A description of the experimental design and treatments can be found in this Readme file in the PortalDate repo.

For now, we are just going to use the Portal_plots table file to look at how the treatments for individual plots have changed over time. Note that this file is already loaded in as the plots_table from the loadData function we ran previously.

#>       year          month             plot        treatment        
#>  Min.   :1977   Min.   : 1.000   Min.   : 1.00   Length:10760      
#>  1st Qu.:1988   1st Qu.: 4.000   1st Qu.: 6.00   Class :character  
#>  Median :1998   Median : 7.000   Median :12.00   Mode  :character  
#>  Mean   :1998   Mean   : 6.552   Mean   :12.48                     
#>  3rd Qu.:2008   3rd Qu.:10.000   3rd Qu.:18.00                     
#>  Max.   :2018   Max.   :12.000   Max.   :24.00                     
#>  resourcetreatment  anttreatment      
#>  Length:10760       Length:10760      
#>  Class :character   Class :character  
#>  Mode  :character   Mode  :character  

We want a proper date variable as well as converting plot into a factor:

plot_treatments <- data_tables$plots_table %>%
  mutate(iso_date = as.Date(paste0(year, "-", month, "-", "01")), 
         plot = as.factor(plot)) %>%
  select(iso_date, plot, treatment)

Figure: plot treatments over time

Treatments of Plots by Date

Treatments of Plots by Date

Identifying control plots

The treatments for the plots have changed over time: in some cases, this was due to initial ramping up of the experimental protocol, in others, exclusions of Dipodomys spectabilis were started and then converted back later because the species went locally extinct (e.g. plots 1, 5, 9, 24).

Abundances over control plots

We are now ready to plot abundances just over the control plots and the time span in 1977-07-01 to 2015-03-01. We do this by retrieving the abundance data by plot, and then filtering accordingly:

Monthly abundance of rodents (control plots)

Monthly abundance of rodents (control plots)

Abundances over rodent exclosures

We can do the same with the “exclosure” condition. First, which plots:

Then, the datespan:

Finally, the figure:

Monthly abundance of rodents (exclosure plots)

Monthly abundance of rodents (exclosure plots)

Since these data have the same number of plots as the previous figure, we can directly compare abundances. Note the decreased numbers for kangaroo rats (Dipodomys spp.) and increased numbers for some other taxa.

Comparison Figure

Let’s merge the two datasets and produce a combined plot: