Functions portal species time series (solution)

Exercise

If surveys.csv, species.csv, and plots.csv are not available in your workspace download them:

Write a function that: * Takes four arguments - 1) a data frame (where each row is one individual and there is a genus and a species column); 2) a column to use as a time column (e.g., year); 3) a genus_name argument for choosing which genus to plot; and 4) a species_name argument for choosing which species to plot. * Makes a plot using ggplot2 with the time on the y-axis and the count of the number of individuals (i.e., the number of rows) observed for that time for the species indicated by the genus_name and species_name arguments. The plot should display the data as blue points (with size = 2) connected by blue lines (with linewidth = 1). The y-axis label Number of Individuals

  1. Use your function, and the data in surveys.csv and species.csv, to plot the time-series for time = year, genus_name = "Dipodomys" and species_name = "merriami"
  2. Use your function, and the data in surveys.csv and species.csv, to plot the time-series for time = month, genus_name = "Chaetodipus" and species_name = "penicillatus" (this plot will show the average seasonal pattern of Chaetodipus penicillatus abundances)
  3. Use your function, and the data from plots.csv, surveys.csv and species.csv, to plot the time-series for time = year, genus_name = "Chaetodipus" and species_name = "baileyi" only on the "Control" plots.
Output solution

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
Rows: 35549 Columns: 9
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): species_id, sex
dbl (7): record_id, month, day, year, plot_id, hindfoot_length, weight

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 54 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (4): species_id, genus, species, taxa

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 24 Columns: 2
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): plot_type
dbl (1): plot_id

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.