Giffee_Ryan_Homework_2_Quarto

Homework 2

Introduction to ggplot

in R for Biol 607 Homework Assignment 2

@date 2023-09-14

@author Ryan Giffee

1) Setup: Run some Code

# install.packages("tidyverse")
library(dplyr)

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
library(readr)
library(ggplot2)
library(forcats)


theme_set(theme_bw(base_size=12))

ice <- read_csv("http://biol607.github.io/homework/data/NH_seaice_extent_monthly_1978_2016.csv") %>%
  mutate(Month_Name = factor(Month_Name),
         Month_Name = fct_reorder(Month_Name, Month))
Rows: 458 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): Month_Name
dbl (5): Year, Month, Day, Extent, Missing

ℹ 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.
# install.packages(c("ggridges", "ggdist"))
# install.packages("ggplot2")

pacman::p_load(ggplot2, ggridges)
str(ice)
tibble [458 × 6] (S3: tbl_df/tbl/data.frame)
 $ Year      : num [1:458] 1978 1978 1979 1979 1979 ...
 $ Month     : num [1:458] 11 12 2 3 6 7 9 10 1 3 ...
 $ Day       : num [1:458] 1 1 1 1 1 1 1 1 1 1 ...
 $ Extent    : num [1:458] 10.7 12.7 15.9 16.6 13.1 ...
 $ Missing   : num [1:458] 0 0 0 0 0 0 0 0 0 0 ...
 $ Month_Name: Factor w/ 12 levels "Jan","Feb","Mar",..: 11 12 2 3 6 7 9 10 1 3 ...

2) Make a box plot for sea ice variability in ice extent every month.

ggplot(data = ice,
       mapping = aes(x = Month_Name,
                     y = Extent)) +
  geom_boxplot()

3) Use ggridgelines to do the same thing

ggplot(data = ice,
       mapping = aes(x = Extent,
                     y = Month_Name)) +
  geom_density_ridges()
Picking joint bandwidth of 0.297

4) Making groups from the continuous using cut functions

ggplot(data = ice,
       mapping = aes(x = Year,
                     y = Extent,
                     group = Month_Name)) +
  facet_wrap(vars(cut_interval(Month, n=4))) +
  geom_line()

5 Use color to show monthly sea ice extent with every year as a line

ggplot(data = ice,
       mapping = aes(x = Month_Name,
                     y = Extent,
                     group = Year,
                     color = Year,
                     palette("blues9"))) +
  geom_line()

Meta 1

I had no knowledge of data visualization in r prior to this assignment. I feel like a learned a lot and had to muscle my way through some of the questions with trial and error, as well as some help from Cooper.

Meta 2

My favorite thing about data visualization is seeing the final product come together to something that’s aesthetically pleasing. Seeing question 5 come together with a nice color palette was very rewarding. It makes me excited to think about using my own data to tell a story.

Meta 3

This took me roughly 3-4 hours after struggling in the beginning, going to office hours, and then finalizing everything. It would be helpful to add some clearer instructions into the homework, specifically on the format of running code. This has been the biggest challenge so far. Learning how to code as well as the intricacies of r has been difficult. I think I learn quickly when given those instructions, and get into a good work flow, but the first few weeks have been especially difficult while trying to get my footing in the structure of the class.

Meta 4

I feel good about this work. It took some muscling and some digging into past scripts, but I think the final product is strong.