Portal Species Time-Series (Functions)
If surveys.csv, species.csv, and plots.csv are not available in your workspace download them:
Load them into R using read_csv()
.
First, combine the surveys
and species
tables into a single data frame.
Then, write a function that:
- Takes three arguments - a data frame (the combined table created in (1)), a
genus
name, and aspecies
name - Uses
dplyr
to produce a data frame with a two columns:year
andcount
, wherecount
is the number of individuals (i.e., the number of rows) for the species indicated bygenus
andspecies
in thatyear
- Make a graph of the resulting time-series using
ggplot2
that hasyear
on the x axis,count
on the y axis, and displays the data as blue points (with size = 2) connected by blue lines (with linewidth = 1). Change the x-axis label toYear
and the y-axis label toNumber of Individuals
- Use your function to plot the time-series for
genus
="Dipodomys"
andspecies
="merriami"
- Use your function to plot the time-series for
genus
="Chaetodipus"
andspecies
="penicillatus"