Skip to content

Commit

Permalink
editing and streamlining lobster report practice session. Making sure…
Browse files Browse the repository at this point in the history
… owner and collab had the same questions and fixing questions number
  • Loading branch information
camilavargasp committed Oct 4, 2024
1 parent 26b1b9f commit b8dcbfb
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 69 deletions.
27 changes: 16 additions & 11 deletions materials/sections/r-practice-clean-wrangle-visualize.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ These exercises will be using data on abundance, size, and trap counts (fishing

1. Create a new repository with a partner
a. Determine who is the Owner and who is the Collaborator
b. The Owner creates a repository on GitHub titled with both your names (i.e. If Angel and Camila were partners, and Angel is the Owner, she would create a repo called `angel-camila`)
b. The Owner creates a repository on GitHub titled with both your names (i.e. If Casey and Camila were partners, and Casey is the Owner, she would create a repo called `casey-camila`)
i. When creating the repository, add a brief description (i.e. R Practice Session: Collaborating on, Wrangling & Visualizing Data), keep the repo Public, and Initialize the repo with a `README` file and an R `.gitignore` template.
c. The Owner adds the Collaborator to the repo
d. Both the Collaborator and the Owner clone the repo into their RStudio
e. Both the Collaborator and the Owner run ```git config pull.rebase false``` in the Terminal to set the `Git` default strategy for `Pull`ing
<!-- e. Both the Collaborator and the Owner run ```git config pull.rebase false``` in the Terminal to set the `Git` default strategy for `Pull`ing -->

**Step 2 and Step 3 are meant <u>to be completed at the same time</u>.
- Collaborator completes Step 2
- Owner completes Step 3

**Step 2 and Step 3 are meant to be completed at the same time. Step 2 is for the Collaborator to complete, and Step 3 is for the Owner to complete.**

2. **Collaborator** creates new files for exercise
a. The Collaborator creates the following directory:
a. The Collaborator creates the following directory (folder):
i. `analysis`
b. After creating the directories, create the following Quarto Documents and store them in the listed folders:
i. Title it: "Owner Analysis", save it as: `owner-analysis.qmd`, and store in `analysis` folder
ii. Title it: "Collaborator Analysis", save it as: `collaborator-analysis.qmd`, and store in `analysis` folder
iii. Title it: "Lobster Report" and save it as: `lobster-report.qmd` (do not need to put in a folder)
iii. Title it: "Lobster Report" and save it as: `lobster-report.qmd` and store in `analysis` folder
b. After creating the files, the Collaborator will `stage (add)`, `commit`, write a commit message, `pull`, and `push` the files to the remote repository (on GitHub)
c. The Owner `pull`s the changes and Quarto Documents into their local repository (their workspace)

Expand All @@ -56,7 +59,9 @@ These exercises will be using data on abundance, size, and trap counts (fishing

### Explore, clean and wrangle data

For this portion of the exercise, the Owner will be working with the lobster abundance and size data, and the Collaborator will be working with the lobster trap buoy counts data
For this portion of the exercise, the
- <u>Owner</u> will be working with the **lobster abundance and size data**
- <u>Collaborator</u> will be working with the **lobster trap buoy counts data**

Questions 1-3 you will be working independently since you're working with different data frames, but you're welcome to check in with each other.

Expand Down Expand Up @@ -106,13 +111,13 @@ Make sure your Quarto Document is well organized and includes the following elem
- citation of the data
- brief summary of the abstract (i.e. 1-2 sentences) from the [EDI Portal](https://portal.edirepository.org/nis/mapbrowse?packageid=knb-lter-sbc.77.8)
- Owner analysis and visualizations (you choose which plots you want to include)
- add alternative text to your plots
- plots can be added either with the data visualization code or with Markdown syntax - it's up to you if you want to include the code or not.
- Try adding alternative text to your plots (See [Quarto Documentation](https://quarto.org/docs/authoring/figures.html#alt-text))
- Plots can be added either with the data visualization code or with Markdown syntax (calling a saved image) - it's up to you if you want to include the code or not.
- Collaborator analysis and visualizations (you choose which plots you want to include)
- add alternative text to your plots
- plots can be added either with the data visualization code or with Markdown syntax - it's up to you if you want to include the code or not.
- Try adding alternative text to your plots (See [Quarto Documentation](https://quarto.org/docs/authoring/figures.html#alt-text))
- plots can be added either with the data visualization code or with Markdown syntax (calling a saved image) - it's up to you if you want to include the code or not.

Finally, publish on GitHub pages (from Owner's repository). Refer back to [Chapter 11](https://learning.nceas.ucsb.edu/2024-02-arctic/session_10.html) for steps on how to publish using GitHub pages.
Finally, publish on GitHub pages (from Owner's repository). Refer back to [Chapter 12](https://learning.nceas.ucsb.edu/2024-10-coreR/session_12.html) for steps on how to publish using GitHub pages.


## Bonus: Add marine protected area (MPA) designation to the data
Expand Down
27 changes: 14 additions & 13 deletions materials/sections/r-practice-collaborator-clean-wrangle.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ library(here)

```{r}
#| code-fold: false
lobster_traps <- read_csv(here("data/Lobster_Trap_Counts_All_Years_20210519.csv"))
lobster_traps <- read_csv(here::here("data/Lobster_Trap_Counts_All_Years_20210519.csv"))
```

4. Look at your data. Take a minute to explore what your data structure looks like, what data types are in the data frame, or use a function to get a high-level summary of the data you're working with.
Expand Down Expand Up @@ -73,11 +73,22 @@ carp_20_traps <- lobster_traps %>%
filter(SITE == "CARP" & TRAPS > 20)
```

# Question 4
Find the maximum number of commercial trap floats using `max()` and group by `SITE` and `MONTH`. Think about how you want to treat the `NA` values in `TRAPS` (Hint: check the arguments in `max()`). Check your output.

```{r}
#| echo: false
# `group_by() %>% summarize()` practice
max_lobster_traps <- lobster_traps %>%
group_by(SITE, MONTH) %>%
summarize(MAX_TRAPS = max(TRAPS, na.rm = TRUE))
```


::: callout-important

## Save your work and use Git
Don't forget the Git workflow! After you've completed the exercises or reached a significant stopping point, use the workflow: ```Stage (add) -> Commit -> Pull -> Push```
## Save your work and Don't forget the Git and GitHub workflow!
After you've completed the exercises or reached a significant stopping point, use the workflow: ```Stage (add) -> Commit -> Pull -> Push```
:::


Expand Down Expand Up @@ -108,14 +119,4 @@ mean_lobster_traps <- lobster_traps %>%
summarize(MEAN_TRAPS = mean(TRAPS, na.rm = TRUE))
```

<!--# Question 6 -->
<!--# Find the maximum number of commercial trap floats using `max()` and group by `SITE` and `MONTH`. Think about how you want to treat the `NA` values in `TRAPS`. Check your output. -->

```{r}
#| echo: false
# `group_by() %>% summarize()` practice
max_lobster_traps <- lobster_traps %>%
group_by(SITE, MONTH) %>%
summarize(MAX_TRAPS = max(TRAPS, na.rm = TRUE))
```

16 changes: 8 additions & 8 deletions materials/sections/r-practice-collaborator-visualize.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ format: html

**Structure of the data visualization exercises:**

- Questions 7-9 will have you create the necessary subsets to create the data visualizations, as well as the basic code to create a visualization.
- Question 10, return to the data visualization code you've written and add styling code to it. For this exercise, only add styling code to the visualization you want to include in the `lobster-report.qmd` (start with just one plot and if there's time add styling code to another plot).
- First you will create the necessary subsets to create the data visualizations, as well as the basic code to create a visualization.
- Then, you will return to the data visualization code you've written and add styling code to it. For this exercise, only add styling code to the visualization you want to include in the `lobster-report.qmd` (start with just one plot and if there's time add styling code to another plot).
- Lastly, save the final visualizations to the `figs` folder before collaborating on the `lobster-report.qmd`.
:::

Expand All @@ -30,7 +30,7 @@ lobster_traps <- read_csv("https://portal.edirepository.org/nis/dataviewer?packa
```

::: callout-note
### Question 7
### Question 5
Create a multi-panel plot of lobster commercial traps (`TRAPS`) grouped by year, using `ggplot()`, `geom_histogram()`, and `facet_wrap()`. Use the variable `YEAR` in `facet_wrap()`. Use the object `lobster_traps`.
:::

Expand All @@ -49,7 +49,7 @@ ggplot(data = lobster_traps, aes(x = TRAPS)) +
</details>

::: callout-note
### Question 8
### Question 6

Create a line graph of the number of total lobster commercial traps observed (y-axis) by year (x-axis) in the study, grouped by `SITE`.
:::
Expand Down Expand Up @@ -93,7 +93,7 @@ ggplot(data = lobsters_traps_summarize, aes(x = YEAR, y = TOTAL_TRAPS)) +


::: callout-note
### Question 9
### Question 7
Create a bar graph that shows the amount of high and low fishing pressure of lobster commercial traps at each `SITE` from 2019-2021.
**Note:** The high and low fishing pressure metrics are completely made up and are not based on any known facts.
:::
Expand Down Expand Up @@ -139,7 +139,7 @@ ggplot(data = lobster_traps_fishing_pressure, aes(x = SITE, y = COUNT, fill = FI
</details>

::: callout-note
### Question 10
### Question 8

1. Go back to your visualization code and add some styling code (aka make your plots pretty!). Again, start with one plot and if there's time add styling code to additional plots. Here's a list of functions to help you get started (this is not an exhaustive list!) or revisit the [data visualization lesson](https://learning.nceas.ucsb.edu/2023-04-coreR/session_12.html):

Expand Down Expand Up @@ -167,7 +167,7 @@ ggplot(data = lobster_traps_fishing_pressure, aes(x = SITE, y = COUNT, fill = FI
:::

::: callout-important
## Save your work and use Git
Don't forget the Git workflow! After you've completed the exercises or reached a significant stopping point, use the workflow: ```Stage (add) -> Commit -> Pull -> Push```
## Save your work and Don't forget the Git and GitHub workflow!
After you've completed the exercises or reached a significant stopping point, use the workflow: ```Stage (add) -> Commit -> Pull -> Push```
:::

40 changes: 19 additions & 21 deletions materials/sections/r-practice-owner-clean-wrangle.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ library(here)
```{r}
#| code-fold: false
#| message: false
lobster_abundance <- read_csv(here("data/Lobster_Abundance_All_Years_20220829.csv"))
lobster_abundance <- read_csv(here::here("data/Lobster_Abundance_All_Years_20220829.csv"))
```

4. Look at your data. Take a minute to explore what your data structure looks like, what data types are in the data frame, or use a function to get a high-level summary of the data you're working with.
Expand Down Expand Up @@ -76,13 +76,24 @@ aque_70mm <- lobster_abundance %>%
filter(SITE == "AQUE" & SIZE_MM >= 70)
```

::: callout-important

## Save your work and use Git
Don't forget the Git workflow! After you've completed the exercises or reached a significant stopping point, use the workflow: ```Stage (add) -> Commit -> Pull -> Push```
:::
# Question 4
Find the maximum carapace length using `max()` and group by `SITE` and `MONTH`. Think about how you want to treat the NA values in `SIZE_MM` (Hint: check the arguments in `max()`). Check your output.

```{r}
#| code-summary: "Answer"
# `group_by() %>% summarize()` practice
max_lobster <- lobster_abundance %>%
group_by(SITE, MONTH) %>%
summarize(MAX_LENGTH = max(SIZE_MM, na.rm = TRUE))
```

::: callout-important

## Save your work and don't forget the Git and GitHub workflow!
After you've completed the exercises or reached a significant stopping point, use the workflow: ```Stage (add) -> Commit -> Pull -> Push```
:::

<!--# Extra Questions -->

Expand All @@ -97,26 +108,13 @@ lobster_cm <- lobster_abundance %>%
mutate(SIZE_CM = SIZE_MM / 10)
```

<!--# Question 5 -->
<!--# Find the mean of lobster carapace length using `mean()`, and group by `SITE`. Think about how you want to treat the `NA` values in `SIZE_MM` (Hint: check the arguments in `mean()`). Check your output. -->
<!-- # Question 4 -->
<!-- Find the mean of lobster carapace length using `mean()`, and group by `SITE`. Think about how you want to treat the `NA` values in `SIZE_MM` (Hint: check the arguments in `mean()`). Check your output. -->

```{r}
#| echo: false
# `group_by() %>% summarize()` practice
lobster_mean <- lobster_abundance %>%
group_by(SITE) %>%
summarize(MEAN_LENGTH = mean(SIZE_MM, na.rm = TRUE))
```


<!--# Question 6 -->
<!--# Find the maximum carapace length using `max()` and group by `SITE` and `MONTH`. Think about how you want to treat the NA values in `SIZE_MM`. Check your output. -->

```{r}
#| echo: false
#| # `group_by() %>% summarize()` practice
max_lobster <- lobster_abundance %>%
group_by(SITE, MONTH) %>%
summarize(MAX_LENGTH = max(SIZE_MM, na.rm = TRUE))
```

```
33 changes: 17 additions & 16 deletions materials/sections/r-practice-owner-visualize.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ format: html

**Structure of the data visualization exercises:**

- Questions 7-9 will have you create the necessary subsets to create the data visualizations, as well as the basic code to create a visualization.
- Question 10, return to the data visualization code you've written and add styling code to it. For this exercise, only add styling code to the visualization you want to include in the `lobster-report.qmd` (start with just one plot and if there's time add styling code to another plot).
- In this section, you will first have you create the necessary subsets to create the data visualizations, as well as the basic code to create a visualization.
- The next step is to return to the data visualization code you've written and add styling code to it. For this exercise, only add styling code to the visualization you want to include in the `lobster-report.qmd` (start with just one plot and if there's time add styling code to another plot).

- Lastly, save the final visualizations to the `figs` folder before collaborating on the `lobster-report.qmd`.
:::
Expand All @@ -31,13 +31,14 @@ lobster_abundance <- read_csv("https://portal.edirepository.org/nis/dataviewer?p


::: callout-note
### Question 7
### Question 5
Create a multi-panel plot of lobster carapace length (`SIZE_MM`) using `ggplot()`, `geom_histogram()`, and `facet_wrap()`. Use the variable `SITE` in `facet_wrap()`. Use the object `lobster_abundance`.
:::

```{r}
#| code-summary: "Answer"
ggplot(data = lobster_abundance, aes(x = SIZE_MM)) +
ggplot(data = lobster_abundance,
aes(x = SIZE_MM)) +
geom_histogram() +
facet_wrap(~SITE)
```
Expand All @@ -49,7 +50,7 @@ ggplot(data = lobster_abundance, aes(x = SIZE_MM)) +
</details>

::: callout-note
### Question 8
### Question 6

Create a line graph of the number of total lobsters observed (y-axis) by year (x-axis) in the study, grouped by `SITE`.
:::
Expand Down Expand Up @@ -89,23 +90,23 @@ ggplot(data = lobsters_summarize, aes(x = YEAR, y = COUNT)) +
:::
</details>

<!--::: callout-note
### Question 9
::: callout-note
### Question 7
Create a bar graph that shows the amount of small and large sized carapace lobsters at each `SITE` from 2019-2021. **Note:** The small and large metrics are completely made up and are not based on any known facts.
:::

First, you'll need to create a new dataset subset called `lobster_size_lrg`:

- `filter()` for the years 2019, 2020, and 2021
- Add a new column called `SIZE_BIN` that contains the values "small" or "large". A "small" carapace size is <= 70 mm, and a "large" carapace size is greater than 70 mm. Use `mutate()` and `if_else()`. Check your output
- Calculate the number of "small" and "large" sized lobsters using `group()` and `summarize()`. Check your output
- Calculate the number of "small" and "large" sized lobsters using `group()` and `summarize()`. Check your output
- Remove the `NA` values from the subsetted data. Hint: check out `drop_na()`. Check your output

```{r}
#| code-summary: "Answer"
lobster_size_lrg <- lobster_abundance %>%
filter(YEAR %in% c(2019, 2020, 2021)) %>%
mutate(SIZE_BIN = if_else(SIZE_MM <= 70, true = "small", false = "large")) %>%
lobster_size_lrg <- lobster_abundance %>%
filter(YEAR %in% c(2019, 2020, 2021)) %>%
mutate(SIZE_BIN = if_else(SIZE_MM <= 70, true = "small", false = "large")) %>%
group_by(SITE, SIZE_BIN) %>%
summarize(COUNT = n()) %>%
drop_na()
Expand All @@ -128,15 +129,15 @@ ggplot(data = lobster_size_lrg, aes(x = SITE, y = COUNT, fill = SIZE_BIN)) +
<summary>Plots</summary>
::: {#lobster-bar-plots layout-ncol=2}

![Bar plot](images/lobster_size_lrg_bar_plot.png){width="50%"}
![Bar plot](images/lobster_size_lrg_bar_plot.png){width="50%"}

![Dodged bar plot](images/lobster_size_lrg_dodged_plot.png){width="50%"}
:::
</details> -->
</details>


::: callout-note
### Question 9
### Question 8

1. Go back to your visualization code and add some styling code (aka make your plots pretty!). Again, start with one plot and if there's time add styling code to additional plots. Here's a list of functions to help you get started (this is not an exhaustive list!) or revisit the [data visualization lesson](https://learning.nceas.ucsb.edu/2023-04-coreR/session_12.html):

Expand Down Expand Up @@ -164,7 +165,7 @@ ggplot(data = lobster_size_lrg, aes(x = SITE, y = COUNT, fill = SIZE_BIN)) +
:::

::: callout-important
## Save your work and use Git
Don't forget the Git workflow! After you've completed the exercises or reached a significant stopping point, use the workflow: ```Stage (add) -> Commit -> Pull -> Push```
## Save your work and Don't forget the Git and GitHub workflow!
After you've completed the exercises or reached a significant stopping point, use the workflow: ```Stage (add) -> Commit -> Pull -> Push```
:::

1 change: 1 addition & 0 deletions materials/session_14.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ format:
---



{{< include /sections/r-practice-clean-wrangle-visualize.qmd >}}

0 comments on commit b8dcbfb

Please sign in to comment.