class: center, middle, inverse, title-slide # Lec02: More on Graphics ## Stat41: Data Viz ### Prof Amanda Luby ### Swarthmore College --- class: center, middle # Today: (1) A graph critique example (2) Wrap up group discussion from yesterday (20 minutes) (3) Summaries + Questions (4) Project 1 (5) GGplot --- # Penguins!  Source: [`palmerpenguins`](https://github.com/allisonhorst/palmerpenguins) R package, artwork by `@allison_horst` --- ```r library(palmerpenguins) penguins ``` ``` ## # A tibble: 344 x 8 ## species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g ## <fct> <fct> <dbl> <dbl> <int> <int> ## 1 Adelie Torge… 39.1 18.7 181 3750 ## 2 Adelie Torge… 39.5 17.4 186 3800 ## 3 Adelie Torge… 40.3 18 195 3250 ## 4 Adelie Torge… NA NA NA NA ## 5 Adelie Torge… 36.7 19.3 193 3450 ## 6 Adelie Torge… 39.3 20.6 190 3650 ## 7 Adelie Torge… 38.9 17.8 181 3625 ## 8 Adelie Torge… 39.2 19.6 195 4675 ## 9 Adelie Torge… 34.1 18.1 193 3475 ## 10 Adelie Torge… 42 20.2 190 4250 ## # … with 334 more rows, and 2 more variables: sex <fct>, year <int> ``` --- <!-- --> --- ## A quick aside on `penguins`: I'm going to use this dataset a lot for showing quick examples -- It's great for this purpose because it has categorical + quantitative variables, there's natural linear relationships, and it is real data from an actual study! -- It's also an alternative to the `iris` dataset (which you may have seen before) which has similar qualities but looks at different species of iris flowers. -- But the `iris` dataset was originally published in the *Annals of Eugenics* and we don't need that energy in 2021. -- So `penguins` it is! --- class: inverse, center, middle # Group Time! (1) Revisit expectations page and add any new thoughts (2) Graph critiques (similar to what we just did on the penguins graph) (3) Compile any questions or comments about the lab/reading (4) Choose someone to share screen and be a presenter (put an orange sticky note on any graphs you *don't* want to present) ## You have 20 minutes --- class: center, middle # Welcome back! --- class: center, middle # [Project 1](https://aluby.domains.swarthmore.edu/stat041/Projects/proj-1.html) --- count: false .panel1-penguins-auto[ ```r *penguins ``` ] .panel2-penguins-auto[ ``` ## # A tibble: 344 x 8 ## species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g ## <fct> <fct> <dbl> <dbl> <int> <int> ## 1 Adelie Torge… 39.1 18.7 181 3750 ## 2 Adelie Torge… 39.5 17.4 186 3800 ## 3 Adelie Torge… 40.3 18 195 3250 ## 4 Adelie Torge… NA NA NA NA ## 5 Adelie Torge… 36.7 19.3 193 3450 ## 6 Adelie Torge… 39.3 20.6 190 3650 ## 7 Adelie Torge… 38.9 17.8 181 3625 ## 8 Adelie Torge… 39.2 19.6 195 4675 ## 9 Adelie Torge… 34.1 18.1 193 3475 ## 10 Adelie Torge… 42 20.2 190 4250 ## # … with 334 more rows, and 2 more variables: sex <fct>, year <int> ``` ] --- count: false .panel1-penguins-auto[ ```r penguins %>% * ggplot() ``` ] .panel2-penguins-auto[ <!-- --> ] --- count: false .panel1-penguins-auto[ ```r penguins %>% ggplot() + * aes(x = flipper_length_mm) ``` ] .panel2-penguins-auto[ <!-- --> ] --- count: false .panel1-penguins-auto[ ```r penguins %>% ggplot() + aes(x = flipper_length_mm) + * aes(fill = species) ``` ] .panel2-penguins-auto[ <!-- --> ] --- count: false .panel1-penguins-auto[ ```r penguins %>% ggplot() + aes(x = flipper_length_mm) + aes(fill = species) + * geom_histogram(alpha = .6, position = "identity") ``` ] .panel2-penguins-auto[ ``` ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. ``` ``` ## Warning: Removed 2 rows containing non-finite values (stat_bin). ``` <!-- --> ] --- count: false .panel1-penguins-auto[ ```r penguins %>% ggplot() + aes(x = flipper_length_mm) + aes(fill = species) + geom_histogram(alpha = .6, position = "identity") + * labs( * title = "Distribution of Flipper Length by Species" * ) ``` ] .panel2-penguins-auto[ ``` ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. ``` ``` ## Warning: Removed 2 rows containing non-finite values (stat_bin). ``` <!-- --> ] --- count: false .panel1-penguins-auto[ ```r penguins %>% ggplot() + aes(x = flipper_length_mm) + aes(fill = species) + geom_histogram(alpha = .6, position = "identity") + labs( title = "Distribution of Flipper Length by Species" ) + * labs( * x = "Flipper Length (mm)" * ) ``` ] .panel2-penguins-auto[ ``` ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. ``` ``` ## Warning: Removed 2 rows containing non-finite values (stat_bin). ``` <!-- --> ] --- count: false .panel1-penguins-auto[ ```r penguins %>% ggplot() + aes(x = flipper_length_mm) + aes(fill = species) + geom_histogram(alpha = .6, position = "identity") + labs( title = "Distribution of Flipper Length by Species" ) + labs( x = "Flipper Length (mm)" ) + * labs( * y = "Frequency" * ) ``` ] .panel2-penguins-auto[ ``` ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. ``` ``` ## Warning: Removed 2 rows containing non-finite values (stat_bin). ``` <!-- --> ] --- count: false .panel1-penguins-auto[ ```r penguins %>% ggplot() + aes(x = flipper_length_mm) + aes(fill = species) + geom_histogram(alpha = .6, position = "identity") + labs( title = "Distribution of Flipper Length by Species" ) + labs( x = "Flipper Length (mm)" ) + labs( y = "Frequency" ) + * theme_bw() ``` ] .panel2-penguins-auto[ ``` ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. ``` ``` ## Warning: Removed 2 rows containing non-finite values (stat_bin). ``` <!-- --> ] --- count: false .panel1-penguins-auto[ ```r penguins %>% ggplot() + aes(x = flipper_length_mm) + aes(fill = species) + geom_histogram(alpha = .6, position = "identity") + labs( title = "Distribution of Flipper Length by Species" ) + labs( x = "Flipper Length (mm)" ) + labs( y = "Frequency" ) + theme_bw() + * scale_fill_manual(values = c("darkorange","purple","cyan4")) ``` ] .panel2-penguins-auto[ ``` ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. ``` ``` ## Warning: Removed 2 rows containing non-finite values (stat_bin). ``` <!-- --> ] <style> .panel1-penguins-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-penguins-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-penguins-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style>