You are reading in a file that contains oyster data collected from the Guana Tolomato Matanzas NERR. This .xlsx data file contains two sheets: "SPAT" and "OYSTER". For your first task, we are going to be looking at the spat data. (Spat are oyster larvae that have permanently attached themselves to a surface)
After reading in the data and creating the oyster
object, be sure to inspect your data. What kind of variables are you given? How many observations are there? Can you tell if this is a wide or long dataset? Does it appear tidy?
oyster <- read_xlsx(here::here('oysters_gtm.xlsx'), sheet = 'SPAT') %>%
janitor::clean_names()
- What does the
janitor::clean_names()
function do?
-
[YOUR ANSWER HERE]
- Why is it recommended that you use the
here
package?
-
[YOUR ANSWER HERE]
- Identify three functions you can use to inspect your data.
-
[YOUR ANSWER HERE]
This dataset contains date (year
, month
, deployment_date
, retrieval_date
), location (region
, reef
), identification (rep
, shell_id
), and count information (spat_count
).
Create a new dataset where you summarize by calculating the mean number of spat per region
. Remember, with the mean()
function you will need to specify na.rm = TRUE
.
-
Using your
ggplot2
cheatsheet, determine whatgeom_
would be the best for using on a timeseries. Make a plot ofmean_spat
bydeployment_date
and color by region. Depending on yourgeom_
you may either usecolor
and/orfill
aesthetics. -
Remove the label on the legend. (Hint: think about what scale this is representing. Are the variables continuous or discrete?)
-
Assign a theme.
ggplot2
has several good defaults. -
Relabel the axes to something more suitable than the variable names.
EXTRA CHALLENGE
-
Adjust the scale of the y-axis to break by 50s.
-
Adjust the scale of the x-axis to display every year. Hint: use
?scale_x_datetime
for help. The year label will be%Y
.
NOTE: gglot2
defaults where it does not have the data start ON the x-axis. If this bothers you, you could try adding expand = c(0,0)
to the scale_y_continuous()
function in your plot.
Steps 02 and 03 wrangled and then plotted your data. Now, combine both steps into one using pipes %>%
, starting with the oyster
dataset without creating new datasets. (Hint: remember to think of pipes as "...and then..." and write your code in a step-wise way.)
- How might "working within the data frame" be more beneficial than creating new objects each step?
-
[YOUR ANSWER HERE]
A great explanation for this: https://github.com/jennybc/row-oriented-workflows/blob/master/ex01_leave-it-in-the-data-frame.md