class: center, middle, inverse, title-slide .title[ # The Normal Curve ] .subtitle[ ## EDP 613 ] .author[ ### Week 5 ] --- <script> function resizeIframe(obj) { obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px'; } </script>
# Prepping a New R Script 1. Open up a blank R script using the menu path **File > New File > R Script**. -- 2. Save this script as `whatever.R` (replacing the term `whatever`) in your R folder. Remember to note where the file is! -- 3. After you have saved this file as `whatever.R`, go to the menu and this week try running the following alternative to **Session > Set Working Directory > To Source File Location** at the top of your script .center2[ ```r setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) ``` ] --- # Getting ready for this session Get the files >- `Box Office.csv` >- `teampolview.csv` --- and save it in the same location as this script. >- Install the packages `viridis` and `patchwork`. >- Load up `tidyverse` and `viridis` This week try using `pacman` to do it ```r pacman::p_load(tidyverse, patchwork, viridis) ``` --- # Last week's R activity --- ## Load up data ```r boxoffice <- read_csv("Box Office.csv") ``` --- ## Before we go on Thes solutions are just one of **many** ways to get to the actual answer. Your work may and will likely vary. --- ### 1. What is the average number of positive reviews for the top five movies? count: false .panel1-sw1-auto[ ```r *boxoffice ``` ] .panel2-sw1-auto[ ``` # A tibble: 718 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw1-auto[ ```r boxoffice %>% * arrange(Rank) ``` ] .panel2-sw1-auto[ ``` # A tibble: 718 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw1-auto[ ```r boxoffice %>% arrange(Rank) %>% * head(5) ``` ] .panel2-sw1-auto[ ``` # A tibble: 5 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Para… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The … 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Knig… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: Ep… 5/19/99 May 4.75e8 1999 # … with abbreviated variable names ¹ReleaseDate, ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw1-auto[ ```r boxoffice %>% arrange(Rank) %>% head(5) %>% * summarize(mean_pos = * mean(AllPos, * na.rm = TRUE)) ``` ] .panel2-sw1-auto[ ``` # A tibble: 1 × 1 mean_pos <dbl> 1 205. ``` ] --- count: false .panel1-sw1-auto[ ```r boxoffice %>% arrange(Rank) %>% head(5) %>% summarize(mean_pos = mean(AllPos, na.rm = TRUE)) %>% * pull() ``` ] .panel2-sw1-auto[ ``` [1] 205.2 ``` ] <style> .panel1-sw1-auto { color: white; width: 73.5%; hight: 32%; float: top; padding-left: 1%; font-size: 80% } .panel2-sw1-auto { color: white; width: 24.5%; hight: 32%; float: top; padding-left: 1%; font-size: 80% } .panel3-sw1-auto { color: white; width: NA%; hight: 33%; float: top; padding-left: 1%; font-size: 80% } </style> --- ### 2. What are the average number of negative reviews for the bottom five movies? count: false .panel1-sw2-auto[ ```r *boxoffice ``` ] .panel2-sw2-auto[ ``` # A tibble: 718 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw2-auto[ ```r boxoffice %>% * arrange(Rank) ``` ] .panel2-sw2-auto[ ``` # A tibble: 718 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw2-auto[ ```r boxoffice %>% arrange(Rank) %>% * tail(5) ``` ] .panel2-sw2-auto[ ``` # A tibble: 5 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 714 151 45 26 10 Cloverfield (… 1/18/08 Jan 8.00e7 2008 2 715 19 15 3 1 Footloose (19… 2/17/84 Feb 8.00e7 1984 3 716 39 96 6 24 Dear John (So… 2/5/10 Feb 8.00e7 2010 4 717 5 8 0 1 A Star Is Bor… 12/17/… Dec 8.00e7 1976 5 718 46 2 6 0 Fantasia (Dis… 11/13/… Nov 8.00e7 1940 # … with abbreviated variable names ¹ReleaseDate, ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw2-auto[ ```r boxoffice %>% arrange(Rank) %>% tail(5) %>% * summarize(mean_neg = * mean(AllNeg, * na.rm = TRUE)) ``` ] .panel2-sw2-auto[ ``` # A tibble: 1 × 1 mean_neg <dbl> 1 33.2 ``` ] --- count: false .panel1-sw2-auto[ ```r boxoffice %>% arrange(Rank) %>% tail(5) %>% summarize(mean_neg = mean(AllNeg, na.rm = TRUE)) %>% * pull() ``` ] .panel2-sw2-auto[ ``` [1] 33.2 ``` ] <style> .panel1-sw2-auto { color: white; width: 73.5%; hight: 32%; float: top; padding-left: 1%; font-size: 80% } .panel2-sw2-auto { color: white; width: 24.5%; hight: 32%; float: top; padding-left: 1%; font-size: 80% } .panel3-sw2-auto { color: white; width: NA%; hight: 33%; float: top; padding-left: 1%; font-size: 80% } </style> --- ### 3. How were movies released over the years? Provide counts and a visualization. count: false .panel1-sw3-auto[ ```r *boxoffice ``` ] .panel2-sw3-auto[ ``` # A tibble: 718 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw3-auto[ ```r boxoffice %>% * group_by(year) ``` ] .panel2-sw3-auto[ ``` # A tibble: 718 × 10 # Groups: year [55] Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw3-auto[ ```r boxoffice %>% group_by(year) %>% * count(name = "number of movies") ``` ] .panel2-sw3-auto[ ``` # A tibble: 55 × 2 # Groups: year [55] year `number of movies` <dbl> <int> 1 1937 1 2 1939 1 3 1940 2 4 1942 1 5 1950 1 6 1953 1 7 1955 1 8 1956 1 9 1961 1 10 1964 1 # … with 45 more rows ``` ] --- count: false .panel1-sw3-auto[ ```r boxoffice %>% group_by(year) %>% count(name = "number of movies") %>% * ungroup() ``` ] .panel2-sw3-auto[ ``` # A tibble: 55 × 2 year `number of movies` <dbl> <int> 1 1937 1 2 1939 1 3 1940 2 4 1942 1 5 1950 1 6 1953 1 7 1955 1 8 1956 1 9 1961 1 10 1964 1 # … with 45 more rows ``` ] <style> .panel1-sw3-auto { color: white; width: 42%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw3-auto { color: white; width: 56%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw3-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- #### Save as a variable ```r boxoffice_annualnum <- boxoffice %>% group_by(year) %>% count(name = "number of movies") %>% ungroup() ``` --- ### 4. Which measure of central tendency is the best to describe the average number of movies over the years? Since the data is skewed, the median is the best indicator of the true average - Median count: false .panel1-sw4a-auto[ ```r *boxoffice_annualnum ``` ] .panel2-sw4a-auto[ ``` # A tibble: 55 × 2 year `number of movies` <dbl> <int> 1 1937 1 2 1939 1 3 1940 2 4 1942 1 5 1950 1 6 1953 1 7 1955 1 8 1956 1 9 1961 1 10 1964 1 # … with 45 more rows ``` ] --- count: false .panel1-sw4a-auto[ ```r boxoffice_annualnum %>% * summarize(median = * median(`number of movies`, * na.rm = TRUE)) ``` ] .panel2-sw4a-auto[ ``` # A tibble: 1 × 1 median <int> 1 6 ``` ] --- count: false .panel1-sw4a-auto[ ```r boxoffice_annualnum %>% summarize(median = median(`number of movies`, na.rm = TRUE)) %>% * pull() ``` ] .panel2-sw4a-auto[ ``` [1] 6 ``` ] <style> .panel1-sw4a-auto { color: white; width: 44.3333333333333%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw4a-auto { color: white; width: 53.6666666666667%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw4a-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- - Mean count: false .panel1-sw4b-auto[ ```r *boxoffice_annualnum ``` ] .panel2-sw4b-auto[ ``` # A tibble: 55 × 2 year `number of movies` <dbl> <int> 1 1937 1 2 1939 1 3 1940 2 4 1942 1 5 1950 1 6 1953 1 7 1955 1 8 1956 1 9 1961 1 10 1964 1 # … with 45 more rows ``` ] --- count: false .panel1-sw4b-auto[ ```r boxoffice_annualnum %>% * summarize(mean = * mean(`number of movies`, * na.rm = TRUE)) ``` ] .panel2-sw4b-auto[ ``` # A tibble: 1 × 1 mean <dbl> 1 13.1 ``` ] --- count: false .panel1-sw4b-auto[ ```r boxoffice_annualnum %>% summarize(mean = mean(`number of movies`, na.rm = TRUE)) %>% * pull() ``` ] .panel2-sw4b-auto[ ``` [1] 13.05455 ``` ] <style> .panel1-sw4b-auto { color: white; width: 44.3333333333333%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw4b-auto { color: white; width: 53.6666666666667%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw4b-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- - Plot count: false .panel1-sw4c-auto[ ```r *ggplot(boxoffice_annualnum, * aes(year, * `number of movies`, * fill = `number of movies`)) ``` ] .panel2-sw4c-auto[ ![](Slides-Week-5R_files/figure-html/sw4c_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-sw4c-auto[ ```r ggplot(boxoffice_annualnum, aes(year, `number of movies`, fill = `number of movies`)) + * geom_bar(stat = "identity") ``` ] .panel2-sw4c-auto[ ![](Slides-Week-5R_files/figure-html/sw4c_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-sw4c-auto[ ```r ggplot(boxoffice_annualnum, aes(year, `number of movies`, fill = `number of movies`)) + geom_bar(stat = "identity") + * theme_minimal() ``` ] .panel2-sw4c-auto[ ![](Slides-Week-5R_files/figure-html/sw4c_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-sw4c-auto[ ```r ggplot(boxoffice_annualnum, aes(year, `number of movies`, fill = `number of movies`)) + geom_bar(stat = "identity") + theme_minimal() + * scale_fill_viridis_c(direction = -1) ``` ] .panel2-sw4c-auto[ ![](Slides-Week-5R_files/figure-html/sw4c_auto_04_output-1.png)<!-- --> ] <style> .panel1-sw4c-auto { color: white; width: 44.3333333333333%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw4c-auto { color: white; width: 53.6666666666667%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw4c-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- <img src="Slides-Week-5R_files/figure-html/unnamed-chunk-7-1.png" style="display: block; margin: auto;" /> --- ### 5. Which year has the most number of ranked movies? count: false .panel1-sw5a-auto[ ```r *boxoffice ``` ] .panel2-sw5a-auto[ ``` # A tibble: 718 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw5a-auto[ ```r boxoffice %>% * group_by(year) ``` ] .panel2-sw5a-auto[ ``` # A tibble: 718 × 10 # Groups: year [55] Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw5a-auto[ ```r boxoffice %>% group_by(year) %>% * tally() ``` ] .panel2-sw5a-auto[ ``` # A tibble: 55 × 2 year n <dbl> <int> 1 1937 1 2 1939 1 3 1940 2 4 1942 1 5 1950 1 6 1953 1 7 1955 1 8 1956 1 9 1961 1 10 1964 1 # … with 45 more rows ``` ] --- count: false .panel1-sw5a-auto[ ```r boxoffice %>% group_by(year) %>% tally() %>% * rename(`number of movies` = n) ``` ] .panel2-sw5a-auto[ ``` # A tibble: 55 × 2 year `number of movies` <dbl> <int> 1 1937 1 2 1939 1 3 1940 2 4 1942 1 5 1950 1 6 1953 1 7 1955 1 8 1956 1 9 1961 1 10 1964 1 # … with 45 more rows ``` ] --- count: false .panel1-sw5a-auto[ ```r boxoffice %>% group_by(year) %>% tally() %>% rename(`number of movies` = n) %>% * ungroup() ``` ] .panel2-sw5a-auto[ ``` # A tibble: 55 × 2 year `number of movies` <dbl> <int> 1 1937 1 2 1939 1 3 1940 2 4 1942 1 5 1950 1 6 1953 1 7 1955 1 8 1956 1 9 1961 1 10 1964 1 # … with 45 more rows ``` ] --- count: false .panel1-sw5a-auto[ ```r boxoffice %>% group_by(year) %>% tally() %>% rename(`number of movies` = n) %>% ungroup() %>% * filter(`number of movies` == * max(`number of movies`)) ``` ] .panel2-sw5a-auto[ ``` # A tibble: 1 × 2 year `number of movies` <dbl> <int> 1 2010 43 ``` ] <style> .panel1-sw5a-auto { color: white; width: 73.5%; hight: 32%; float: top; padding-left: 1%; font-size: 80% } .panel2-sw5a-auto { color: white; width: 24.5%; hight: 32%; float: top; padding-left: 1%; font-size: 80% } .panel3-sw5a-auto { color: white; width: NA%; hight: 33%; float: top; padding-left: 1%; font-size: 80% } </style> --- *or* count: false .panel1-sw5b-auto[ ```r *boxoffice ``` ] .panel2-sw5b-auto[ ``` # A tibble: 718 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw5b-auto[ ```r boxoffice %>% * group_by(year) ``` ] .panel2-sw5b-auto[ ``` # A tibble: 718 × 10 # Groups: year [55] Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw5b-auto[ ```r boxoffice %>% group_by(year) %>% * summarise(`number of movies` = n()) ``` ] .panel2-sw5b-auto[ ``` # A tibble: 55 × 2 year `number of movies` <dbl> <int> 1 1937 1 2 1939 1 3 1940 2 4 1942 1 5 1950 1 6 1953 1 7 1955 1 8 1956 1 9 1961 1 10 1964 1 # … with 45 more rows ``` ] --- count: false .panel1-sw5b-auto[ ```r boxoffice %>% group_by(year) %>% summarise(`number of movies` = n()) %>% * ungroup() ``` ] .panel2-sw5b-auto[ ``` # A tibble: 55 × 2 year `number of movies` <dbl> <int> 1 1937 1 2 1939 1 3 1940 2 4 1942 1 5 1950 1 6 1953 1 7 1955 1 8 1956 1 9 1961 1 10 1964 1 # … with 45 more rows ``` ] --- count: false .panel1-sw5b-auto[ ```r boxoffice %>% group_by(year) %>% summarise(`number of movies` = n()) %>% ungroup() %>% * filter(`number of movies` == * max(`number of movies`)) ``` ] .panel2-sw5b-auto[ ``` # A tibble: 1 × 2 year `number of movies` <dbl> <int> 1 2010 43 ``` ] <style> .panel1-sw5b-auto { color: white; width: 42.9333333333333%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw5b-auto { color: white; width: 55.0666666666667%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw5b-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- *or* count: false .panel1-sw5c-auto[ ```r *boxoffice ``` ] .panel2-sw5c-auto[ ``` # A tibble: 718 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw5c-auto[ ```r boxoffice %>% * group_by(year) ``` ] .panel2-sw5c-auto[ ``` # A tibble: 718 × 10 # Groups: year [55] Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-sw5c-auto[ ```r boxoffice %>% group_by(year) %>% * mutate(`number of movies` = n()) ``` ] .panel2-sw5c-auto[ ``` # A tibble: 718 × 11 # Groups: year [55] Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year numbe…⁴ <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> <int> 1 1 238 48 38 3 Avat… 12/18/… Dec 7.61e8 2009 38 2 2 145 21 36 8 Tita… 12/19/… Dec 6.59e8 1997 18 3 3 268 22 38 7 Marv… 5/4/12 May 6.23e8 2012 31 4 4 268 18 42 4 The … 7/18/08 Jul 5.35e8 2008 39 5 5 107 81 19 31 Star… 5/19/99 May 4.75e8 1999 27 6 6 63 4 15 2 Star… 5/25/77 May 4.61e8 1977 5 7 7 256 39 34 11 The … 7/20/12 Jul 4.48e8 2012 31 8 8 185 23 36 5 Shre… 5/19/04 May 4.41e8 2004 33 9 9 92 2 17 1 E.T.… 6/11/82 Jun 4.35e8 1982 5 10 10 119 101 16 25 Pira… 7/7/06 Jul 4.23e8 2006 29 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues, ⁴`number of movies` ``` ] --- count: false .panel1-sw5c-auto[ ```r boxoffice %>% group_by(year) %>% mutate(`number of movies` = n()) %>% * ungroup() ``` ] .panel2-sw5c-auto[ ``` # A tibble: 718 × 11 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year numbe…⁴ <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> <int> 1 1 238 48 38 3 Avat… 12/18/… Dec 7.61e8 2009 38 2 2 145 21 36 8 Tita… 12/19/… Dec 6.59e8 1997 18 3 3 268 22 38 7 Marv… 5/4/12 May 6.23e8 2012 31 4 4 268 18 42 4 The … 7/18/08 Jul 5.35e8 2008 39 5 5 107 81 19 31 Star… 5/19/99 May 4.75e8 1999 27 6 6 63 4 15 2 Star… 5/25/77 May 4.61e8 1977 5 7 7 256 39 34 11 The … 7/20/12 Jul 4.48e8 2012 31 8 8 185 23 36 5 Shre… 5/19/04 May 4.41e8 2004 33 9 9 92 2 17 1 E.T.… 6/11/82 Jun 4.35e8 1982 5 10 10 119 101 16 25 Pira… 7/7/06 Jul 4.23e8 2006 29 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues, ⁴`number of movies` ``` ] --- count: false .panel1-sw5c-auto[ ```r boxoffice %>% group_by(year) %>% mutate(`number of movies` = n()) %>% ungroup() %>% * distinct(year, .keep_all=TRUE) ``` ] .panel2-sw5c-auto[ ``` # A tibble: 55 × 11 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year numbe…⁴ <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> <int> 1 1 238 48 38 3 Avat… 12/18/… Dec 7.61e8 2009 38 2 2 145 21 36 8 Tita… 12/19/… Dec 6.59e8 1997 18 3 3 268 22 38 7 Marv… 5/4/12 May 6.23e8 2012 31 4 4 268 18 42 4 The … 7/18/08 Jul 5.35e8 2008 39 5 5 107 81 19 31 Star… 5/19/99 May 4.75e8 1999 27 6 6 63 4 15 2 Star… 5/25/77 May 4.61e8 1977 5 7 8 185 23 36 5 Shre… 5/19/04 May 4.41e8 2004 33 8 9 92 2 17 1 E.T.… 6/11/82 Jun 4.35e8 1982 5 9 10 119 101 16 25 Pira… 7/7/06 Jul 4.23e8 2006 29 10 11 84 10 14 1 The … 6/15/94 Jun 4.23e8 1994 14 # … with 45 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues, ⁴`number of movies` ``` ] --- count: false .panel1-sw5c-auto[ ```r boxoffice %>% group_by(year) %>% mutate(`number of movies` = n()) %>% ungroup() %>% distinct(year, .keep_all=TRUE) %>% * filter(`number of movies` == * max(`number of movies`)) ``` ] .panel2-sw5c-auto[ ``` # A tibble: 1 × 11 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year numbe…⁴ <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> <int> 1 12 252 3 41 0 Toy S… 6/18/10 Jun 4.15e8 2010 43 # … with abbreviated variable names ¹ReleaseDate, ²ReleaseMonth, ³Revenues, # ⁴`number of movies` ``` ] --- count: false .panel1-sw5c-auto[ ```r boxoffice %>% group_by(year) %>% mutate(`number of movies` = n()) %>% ungroup() %>% distinct(year, .keep_all=TRUE) %>% filter(`number of movies` == max(`number of movies`)) %>% * select(year, `number of movies`) ``` ] .panel2-sw5c-auto[ ``` # A tibble: 1 × 2 year `number of movies` <dbl> <int> 1 2010 43 ``` ] <style> .panel1-sw5c-auto { color: white; width: 43.1943127962085%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-sw5c-auto { color: white; width: 54.8056872037915%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-sw5c-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ### Imaginary bonus: What are the top ranked movie by year? count: false .panel1-swiba-auto[ ```r *boxoffice ``` ] .panel2-swiba-auto[ ``` # A tibble: 718 × 10 Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-swiba-auto[ ```r boxoffice %>% * group_by(year) ``` ] .panel2-swiba-auto[ ``` # A tibble: 718 × 10 # Groups: year [55] Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 1 238 48 38 3 Avatar (Fox) 12/18/… Dec 7.61e8 2009 2 2 145 21 36 8 Titanic (Par… 12/19/… Dec 6.59e8 1997 3 3 268 22 38 7 Marvel's The… 5/4/12 May 6.23e8 2012 4 4 268 18 42 4 The Dark Kni… 7/18/08 Jul 5.35e8 2008 5 5 107 81 19 31 Star Wars: E… 5/19/99 May 4.75e8 1999 6 6 63 4 15 2 Star Wars (F… 5/25/77 May 4.61e8 1977 7 7 256 39 34 11 The Dark Kni… 7/20/12 Jul 4.48e8 2012 8 8 185 23 36 5 Shrek 2 (Dre… 5/19/04 May 4.41e8 2004 9 9 92 2 17 1 E.T.: The Ex… 6/11/82 Jun 4.35e8 1982 10 10 119 101 16 25 Pirates of t… 7/7/06 Jul 4.23e8 2006 # … with 708 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-swiba-auto[ ```r boxoffice %>% group_by(year) %>% * filter(Rank == max(Rank)) ``` ] .panel2-swiba-auto[ ``` # A tibble: 55 × 10 # Groups: year [55] Rank AllPos AllNeg TopPos TopNeg Movie Relea…¹ Relea…² Reven…³ year <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> 1 128 64 3 15 2 Gone with th… 12/15/… Dec 1.99e8 1939 2 145 39 1 6 0 Snow White a… 12/21/… Dec 1.85e8 1937 3 249 36 1 5 0 101 Dalmatia… 1/25/61 Jan 1.45e8 1961 4 408 36 1 4 0 American Gra… 8/1/73 Aug 1.15e8 1973 5 424 49 2 5 2 One Flew Ove… 11/20/… Nov 1.12e8 1975 6 427 28 5 3 2 Doctor Zhiva… 12/22/… Dec 1.12e8 1965 7 430 7 15 0 1 Porky's (Fox) 3/19/82 Mar 1.11e8 1982 8 473 42 6 5 2 The Graduate… 12/21/… Dec 1.05e8 1967 9 488 41 4 4 0 Bambi (Disne… 8/13/42 Aug 1.03e8 1942 10 496 40 5 3 3 Butch Cassid… 9/23/69 Sep 1.02e8 1969 # … with 45 more rows, and abbreviated variable names ¹ReleaseDate, # ²ReleaseMonth, ³Revenues ``` ] --- count: false .panel1-swiba-auto[ ```r boxoffice %>% group_by(year) %>% filter(Rank == max(Rank)) %>% * select(Rank, Movie, year) ``` ] .panel2-swiba-auto[ ``` # A tibble: 55 × 3 # Groups: year [55] Rank Movie year <dbl> <chr> <dbl> 1 128 Gone with the Wind (MGM) 1939 2 145 Snow White and the Seven Dwarfs (Disney / RKO) 1937 3 249 101 Dalmatians (1961) (Disney) 1961 4 408 American Graffiti (Universal) 1973 5 424 One Flew Over the Cuckoo's Nest (United Artists) 1975 6 427 Doctor Zhivago (MGM) 1965 7 430 Porky's (Fox) 1982 8 473 The Graduate (AVCO Embassy) 1967 9 488 Bambi (Disney / RKO) 1942 10 496 Butch Cassidy and the Sundance Kid (Fox) 1969 # … with 45 more rows ``` ] --- count: false .panel1-swiba-auto[ ```r boxoffice %>% group_by(year) %>% filter(Rank == max(Rank)) %>% select(Rank, Movie, year) %>% * arrange(-year) ``` ] .panel2-swiba-auto[ ``` # A tibble: 55 × 3 # Groups: year [55] Rank Movie year <dbl> <chr> <dbl> 1 658 Wrath of the Titans (Warner Bros.) 2012 2 705 Zookeeper (Sony / Columbia) 2011 3 716 Dear John (Sony / Screen Gems) 2010 4 656 Up in the Air (Paramount) 2009 5 714 Cloverfield (Paramount) 2008 6 711 Disturbia (Paramount / DreamWorks) 2007 7 712 Nacho Libre (Paramount) 2006 8 708 The Dukes of Hazzard (Warner Bros.) 2005 9 706 Alien Vs. Predator (Fox) 2004 10 704 The Texas Chainsaw Massacre (2003) (New Line) 2003 # … with 45 more rows ``` ] --- count: false .panel1-swiba-auto[ ```r boxoffice %>% group_by(year) %>% filter(Rank == max(Rank)) %>% select(Rank, Movie, year) %>% arrange(-year) %>% * ungroup() ``` ] .panel2-swiba-auto[ ``` # A tibble: 55 × 3 Rank Movie year <dbl> <chr> <dbl> 1 658 Wrath of the Titans (Warner Bros.) 2012 2 705 Zookeeper (Sony / Columbia) 2011 3 716 Dear John (Sony / Screen Gems) 2010 4 656 Up in the Air (Paramount) 2009 5 714 Cloverfield (Paramount) 2008 6 711 Disturbia (Paramount / DreamWorks) 2007 7 712 Nacho Libre (Paramount) 2006 8 708 The Dukes of Hazzard (Warner Bros.) 2005 9 706 Alien Vs. Predator (Fox) 2004 10 704 The Texas Chainsaw Massacre (2003) (New Line) 2003 # … with 45 more rows ``` ] <style> .panel1-swiba-auto { color: white; width: 42%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-swiba-auto { color: white; width: 56%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-swiba-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ```r top_movie_year <- boxoffice %>% group_by(year) %>% filter(Rank == max(Rank)) %>% select(Rank, Movie, year) %>% arrange(-year) %>% ungroup() ``` --- #### Numerical count: false .panel1-swibb-auto[ ```r *ggplot(top_movie_year, * aes(year, * Rank, * fill = Movie)) ``` ] .panel2-swibb-auto[ ![](Slides-Week-5R_files/figure-html/swibb_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-swibb-auto[ ```r ggplot(top_movie_year, aes(year, Rank, fill = Movie)) + * geom_bar(stat = "identity", * show.legend = FALSE) ``` ] .panel2-swibb-auto[ ![](Slides-Week-5R_files/figure-html/swibb_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-swibb-auto[ ```r ggplot(top_movie_year, aes(year, Rank, fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + * theme_minimal() ``` ] .panel2-swibb-auto[ ![](Slides-Week-5R_files/figure-html/swibb_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-swibb-auto[ ```r ggplot(top_movie_year, aes(year, Rank, fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + theme_minimal() + * scale_fill_viridis_d(direction = -1) ``` ] .panel2-swibb-auto[ ![](Slides-Week-5R_files/figure-html/swibb_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-swibb-auto[ ```r ggplot(top_movie_year, aes(year, Rank, fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + theme_minimal() + scale_fill_viridis_d(direction = -1) + * labs(title = "Top Movies by Year and Rank", * subtitle = "According to Rotten Tomatoes") ``` ] .panel2-swibb-auto[ ![](Slides-Week-5R_files/figure-html/swibb_auto_05_output-1.png)<!-- --> ] <style> .panel1-swibb-auto { color: white; width: 51.3333333333333%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-swibb-auto { color: white; width: 46.6666666666667%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-swibb-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- #### Categorical count: false .panel1-swibc-auto[ ```r *ggplot(top_movie_year, * aes(year, * Movie, * fill = Movie)) ``` ] .panel2-swibc-auto[ ![](Slides-Week-5R_files/figure-html/swibc_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-swibc-auto[ ```r ggplot(top_movie_year, aes(year, Movie, fill = Movie)) + * geom_bar(stat = "identity", * show.legend = FALSE) ``` ] .panel2-swibc-auto[ ![](Slides-Week-5R_files/figure-html/swibc_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-swibc-auto[ ```r ggplot(top_movie_year, aes(year, Movie, fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + * theme_minimal() ``` ] .panel2-swibc-auto[ ![](Slides-Week-5R_files/figure-html/swibc_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-swibc-auto[ ```r ggplot(top_movie_year, aes(year, Movie, fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + theme_minimal() + * scale_fill_viridis_d(direction = -1) ``` ] .panel2-swibc-auto[ ![](Slides-Week-5R_files/figure-html/swibc_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-swibc-auto[ ```r ggplot(top_movie_year, aes(year, Movie, fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + theme_minimal() + scale_fill_viridis_d(direction = -1) + * labs(title = "Top Movies by Year", * subtitle = "According to Rotten Tomatoes") ``` ] .panel2-swibc-auto[ ![](Slides-Week-5R_files/figure-html/swibc_auto_05_output-1.png)<!-- --> ] <style> .panel1-swibc-auto { color: white; width: 51.3333333333333%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-swibc-auto { color: white; width: 46.6666666666667%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-swibc-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- That looks off. Let's try -- - reordering the bars which we can do a command called `reorder()` -- - setting limits on the horizontal axis which we can do with a command called `xlim()` -- count: false .panel1-swibd-auto[ ```r *ggplot(top_movie_year, * aes(year, * reorder(Movie, -year), * fill = Movie)) ``` ] .panel2-swibd-auto[ ![](Slides-Week-5R_files/figure-html/swibd_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-swibd-auto[ ```r ggplot(top_movie_year, aes(year, reorder(Movie, -year), fill = Movie)) + * geom_bar(stat = "identity", * show.legend = FALSE) ``` ] .panel2-swibd-auto[ ![](Slides-Week-5R_files/figure-html/swibd_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-swibd-auto[ ```r ggplot(top_movie_year, aes(year, reorder(Movie, -year), fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + * theme_minimal() ``` ] .panel2-swibd-auto[ ![](Slides-Week-5R_files/figure-html/swibd_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-swibd-auto[ ```r ggplot(top_movie_year, aes(year, reorder(Movie, -year), fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + theme_minimal() + * scale_fill_viridis_d(direction = -1) ``` ] .panel2-swibd-auto[ ![](Slides-Week-5R_files/figure-html/swibd_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-swibd-auto[ ```r ggplot(top_movie_year, aes(year, reorder(Movie, -year), fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + theme_minimal() + scale_fill_viridis_d(direction = -1) + * labs(title = "Top Movies by Year", * subtitle = "According to Rotten Tomatoes") ``` ] .panel2-swibd-auto[ ![](Slides-Week-5R_files/figure-html/swibd_auto_05_output-1.png)<!-- --> ] --- count: false .panel1-swibd-auto[ ```r ggplot(top_movie_year, aes(year, reorder(Movie, -year), fill = Movie)) + geom_bar(stat = "identity", show.legend = FALSE) + theme_minimal() + scale_fill_viridis_d(direction = -1) + labs(title = "Top Movies by Year", subtitle = "According to Rotten Tomatoes") + * coord_cartesian(xlim = c(1900, 2015)) ``` ] .panel2-swibd-auto[ ![](Slides-Week-5R_files/figure-html/swibd_auto_06_output-1.png)<!-- --> ] <style> .panel1-swibd-auto { color: white; width: 51.3333333333333%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-swibd-auto { color: white; width: 46.6666666666667%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-swibd-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- Ok now on to the normal curve! --- ## Load up data ```r nfl_pol <- read_csv("teampolview.csv") ``` --- ## Data Wrangling count: false .panel1-swwrangle-auto[ ```r *nfl_pol ``` ] .panel2-swwrangle-auto[ ``` # A tibble: 33 × 25 Team Total…¹ Total…² Asian…³ Black…⁴ Hispa…⁵ White…⁶ Other…⁷ Total…⁸ Asian…⁹ <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 Ariz… 148 39 2 7 7 20 3 71 4 2 Atla… 188 59 3 27 5 23 1 75 3 3 Balt… 150 56 5 14 3 30 4 65 3 4 Buff… 92 22 2 3 1 15 1 46 7 5 Caro… 164 51 4 16 3 26 2 64 3 6 Chic… 285 94 5 16 8 63 2 129 9 7 Cinc… 106 37 0 6 1 29 1 32 2 8 Clev… 105 34 2 3 3 24 2 42 3 9 Dall… 438 128 5 30 17 66 10 170 9 10 Denv… 313 100 4 15 7 68 6 122 3 # … with 23 more rows, 15 more variables: `Black Independent` <dbl>, # `Hispanic Independent` <dbl>, `White Independent` <dbl>, # `Other Independent` <dbl>, `Total Republican` <dbl>, # `Asian Republican` <dbl>, `Black Republican` <dbl>, # `Hispanic Republican` <dbl>, Republican <dbl>, `Other Republican` <dbl>, # `GOP%` <chr>, `Dem%` <chr>, `Ind%` <chr>, `White%` <chr>, # `Nonwhite%` <chr>, and abbreviated variable names ¹`Total Respondents`, … ``` ] --- count: false .panel1-swwrangle-auto[ ```r nfl_pol %>% * select(Team, * `Total Respondents`, `Total Democrats`, * Republican, `Other Republican`) ``` ] .panel2-swwrangle-auto[ ``` # A tibble: 33 × 5 Team `Total Respondents` `Total Democrats` Republican Other R…¹ <chr> <dbl> <dbl> <dbl> <dbl> 1 Arizona Cardinals 148 39 30 2 2 Atlanta Falcons 188 59 41 3 3 Baltimore Ravens 150 56 26 1 4 Buffalo Bills 92 22 16 0 5 Carolina Panthers 164 51 44 1 6 Chicago Bears 285 94 54 1 7 Cincinnati Bengals 106 37 30 2 8 Cleveland Browns 105 34 26 2 9 Dallas Cowboys 438 128 123 6 10 Denver Broncos 313 100 84 3 # … with 23 more rows, and abbreviated variable name ¹`Other Republican` ``` ] --- count: false .panel1-swwrangle-auto[ ```r nfl_pol %>% select(Team, `Total Respondents`, `Total Democrats`, Republican, `Other Republican`) %>% * rowwise(Team) ``` ] .panel2-swwrangle-auto[ ``` # A tibble: 33 × 5 # Rowwise: Team Team `Total Respondents` `Total Democrats` Republican Other R…¹ <chr> <dbl> <dbl> <dbl> <dbl> 1 Arizona Cardinals 148 39 30 2 2 Atlanta Falcons 188 59 41 3 3 Baltimore Ravens 150 56 26 1 4 Buffalo Bills 92 22 16 0 5 Carolina Panthers 164 51 44 1 6 Chicago Bears 285 94 54 1 7 Cincinnati Bengals 106 37 30 2 8 Cleveland Browns 105 34 26 2 9 Dallas Cowboys 438 128 123 6 10 Denver Broncos 313 100 84 3 # … with 23 more rows, and abbreviated variable name ¹`Other Republican` ``` ] --- count: false .panel1-swwrangle-auto[ ```r nfl_pol %>% select(Team, `Total Respondents`, `Total Democrats`, Republican, `Other Republican`) %>% rowwise(Team) %>% * mutate(`Total Republicans` = sum(c(Republican,`Other Republican`))) ``` ] .panel2-swwrangle-auto[ ``` # A tibble: 33 × 6 # Rowwise: Team Team `Total Respondents` Total Democr…¹ Repub…² Other…³ Total…⁴ <chr> <dbl> <dbl> <dbl> <dbl> <dbl> 1 Arizona Cardinals 148 39 30 2 32 2 Atlanta Falcons 188 59 41 3 44 3 Baltimore Ravens 150 56 26 1 27 4 Buffalo Bills 92 22 16 0 16 5 Carolina Panthers 164 51 44 1 45 6 Chicago Bears 285 94 54 1 55 7 Cincinnati Bengals 106 37 30 2 32 8 Cleveland Browns 105 34 26 2 28 9 Dallas Cowboys 438 128 123 6 129 10 Denver Broncos 313 100 84 3 87 # … with 23 more rows, and abbreviated variable names ¹`Total Democrats`, # ²Republican, ³`Other Republican`, ⁴`Total Republicans` ``` ] --- count: false .panel1-swwrangle-auto[ ```r nfl_pol %>% select(Team, `Total Respondents`, `Total Democrats`, Republican, `Other Republican`) %>% rowwise(Team) %>% mutate(`Total Republicans` = sum(c(Republican,`Other Republican`))) %>% * select(-c(Republican,`Other Republican`)) ``` ] .panel2-swwrangle-auto[ ``` # A tibble: 33 × 4 # Rowwise: Team Team `Total Respondents` `Total Democrats` `Total Republicans` <chr> <dbl> <dbl> <dbl> 1 Arizona Cardinals 148 39 32 2 Atlanta Falcons 188 59 44 3 Baltimore Ravens 150 56 27 4 Buffalo Bills 92 22 16 5 Carolina Panthers 164 51 45 6 Chicago Bears 285 94 55 7 Cincinnati Bengals 106 37 32 8 Cleveland Browns 105 34 28 9 Dallas Cowboys 438 128 129 10 Denver Broncos 313 100 87 # … with 23 more rows ``` ] --- count: false .panel1-swwrangle-auto[ ```r nfl_pol %>% select(Team, `Total Respondents`, `Total Democrats`, Republican, `Other Republican`) %>% rowwise(Team) %>% mutate(`Total Republicans` = sum(c(Republican,`Other Republican`))) %>% select(-c(Republican,`Other Republican`)) %>% * mutate(percent_dem = round(`Total Democrats`/`Total Respondents`,2)) ``` ] .panel2-swwrangle-auto[ ``` # A tibble: 33 × 5 # Rowwise: Team Team `Total Respondents` `Total Democrats` Total Repu…¹ perce…² <chr> <dbl> <dbl> <dbl> <dbl> 1 Arizona Cardinals 148 39 32 0.26 2 Atlanta Falcons 188 59 44 0.31 3 Baltimore Ravens 150 56 27 0.37 4 Buffalo Bills 92 22 16 0.24 5 Carolina Panthers 164 51 45 0.31 6 Chicago Bears 285 94 55 0.33 7 Cincinnati Bengals 106 37 32 0.35 8 Cleveland Browns 105 34 28 0.32 9 Dallas Cowboys 438 128 129 0.29 10 Denver Broncos 313 100 87 0.32 # … with 23 more rows, and abbreviated variable names ¹`Total Republicans`, # ²percent_dem ``` ] --- count: false .panel1-swwrangle-auto[ ```r nfl_pol %>% select(Team, `Total Respondents`, `Total Democrats`, Republican, `Other Republican`) %>% rowwise(Team) %>% mutate(`Total Republicans` = sum(c(Republican,`Other Republican`))) %>% select(-c(Republican,`Other Republican`)) %>% mutate(percent_dem = round(`Total Democrats`/`Total Respondents`,2)) %>% * mutate(percent_rep = round(`Total Republicans`/`Total Respondents`,2)) ``` ] .panel2-swwrangle-auto[ ``` # A tibble: 33 × 6 # Rowwise: Team Team `Total Respondents` Total Democr…¹ Total…² perce…³ perce…⁴ <chr> <dbl> <dbl> <dbl> <dbl> <dbl> 1 Arizona Cardinals 148 39 32 0.26 0.22 2 Atlanta Falcons 188 59 44 0.31 0.23 3 Baltimore Ravens 150 56 27 0.37 0.18 4 Buffalo Bills 92 22 16 0.24 0.17 5 Carolina Panthers 164 51 45 0.31 0.27 6 Chicago Bears 285 94 55 0.33 0.19 7 Cincinnati Bengals 106 37 32 0.35 0.3 8 Cleveland Browns 105 34 28 0.32 0.27 9 Dallas Cowboys 438 128 129 0.29 0.29 10 Denver Broncos 313 100 87 0.32 0.28 # … with 23 more rows, and abbreviated variable names ¹`Total Democrats`, # ²`Total Republicans`, ³percent_dem, ⁴percent_rep ``` ] <style> .panel1-swwrangle-auto { color: white; width: 73.5%; hight: 32%; float: top; padding-left: 1%; font-size: 80% } .panel2-swwrangle-auto { color: white; width: 24.5%; hight: 32%; float: top; padding-left: 1%; font-size: 80% } .panel3-swwrangle-auto { color: white; width: NA%; hight: 33%; float: top; padding-left: 1%; font-size: 80% } </style> --- ## Give it a variable ```r nfl_percentages <- nfl_pol %>% select(Team, `Total Respondents`, `Total Democrats`, Republican, `Other Republican`) %>% rowwise(Team) %>% mutate(`Total Republicans` = sum(c(Republican,`Other Republican`))) %>% select(-c(Republican, `Other Republican`)) %>% mutate(percent_dem = round(`Total Democrats`/`Total Respondents`,2)) %>% mutate(percent_rep = round(`Total Republicans`/`Total Respondents`,2)) ``` --- ## Plot for Democrats by Team count: false .panel1-swdems-auto[ ```r *ggplot(nfl_percentages, * aes(reorder(Team, percent_dem), * percent_dem, * fill = percent_dem)) ``` ] .panel2-swdems-auto[ ![](Slides-Week-5R_files/figure-html/swdems_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-swdems-auto[ ```r ggplot(nfl_percentages, aes(reorder(Team, percent_dem), percent_dem, fill = percent_dem)) + * geom_bar(stat="identity") ``` ] .panel2-swdems-auto[ ![](Slides-Week-5R_files/figure-html/swdems_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-swdems-auto[ ```r ggplot(nfl_percentages, aes(reorder(Team, percent_dem), percent_dem, fill = percent_dem)) + geom_bar(stat="identity") + * coord_flip() ``` ] .panel2-swdems-auto[ ![](Slides-Week-5R_files/figure-html/swdems_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-swdems-auto[ ```r ggplot(nfl_percentages, aes(reorder(Team, percent_dem), percent_dem, fill = percent_dem)) + geom_bar(stat="identity") + coord_flip() + * theme_minimal() ``` ] .panel2-swdems-auto[ ![](Slides-Week-5R_files/figure-html/swdems_auto_04_output-1.png)<!-- --> ] <style> .panel1-swdems-auto { color: white; width: 46.6666666666667%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-swdems-auto { color: white; width: 51.3333333333333%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-swdems-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## Plot for Republicans by Team count: false .panel1-swgops-auto[ ```r *ggplot(nfl_percentages, * aes(reorder(Team, percent_rep), * percent_rep, * fill = percent_rep)) ``` ] .panel2-swgops-auto[ ![](Slides-Week-5R_files/figure-html/swgops_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-swgops-auto[ ```r ggplot(nfl_percentages, aes(reorder(Team, percent_rep), percent_rep, fill = percent_rep)) + * geom_bar(stat="identity") ``` ] .panel2-swgops-auto[ ![](Slides-Week-5R_files/figure-html/swgops_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-swgops-auto[ ```r ggplot(nfl_percentages, aes(reorder(Team, percent_rep), percent_rep, fill = percent_rep)) + geom_bar(stat="identity") + * coord_flip() ``` ] .panel2-swgops-auto[ ![](Slides-Week-5R_files/figure-html/swgops_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-swgops-auto[ ```r ggplot(nfl_percentages, aes(reorder(Team, percent_rep), percent_rep, fill = percent_rep)) + geom_bar(stat="identity") + coord_flip() + * theme_minimal() ``` ] .panel2-swgops-auto[ ![](Slides-Week-5R_files/figure-html/swgops_auto_04_output-1.png)<!-- --> ] <style> .panel1-swgops-auto { color: white; width: 46.6666666666667%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-swgops-auto { color: white; width: 51.3333333333333%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-swgops-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## Let's compare them! But first we need to assign variables ```r p1 <- ggplot(nfl_percentages, aes(reorder(Team, percent_dem), percent_dem, fill = percent_dem)) + geom_bar(stat="identity") + coord_flip() + theme_minimal() ``` ```r p2 <- ggplot(nfl_percentages, aes(reorder(Team, percent_rep), percent_rep, fill = percent_rep)) + geom_bar(stat="identity") + coord_flip() + theme_minimal() ``` --- # Patch it together using `Patchwork` ```r p1 + p2 ``` <img src="Slides-Week-5R_files/figure-html/unnamed-chunk-14-1.png" width="40%" style="display: block; margin: auto;" /> --- ## A better way That's not really a comparison...at least not teamwise! Let's try something different --- ## More Data Wrangling: Going from wide to long using `pivot_longer` <center> <img src="pivot_longer.png" width="800" height="436" alt="Pivot Longer"> </center> <br> --- ### Let's pivot! count: false .panel1-swpivot-auto[ ```r *nfl_percentages ``` ] .panel2-swpivot-auto[ ``` # A tibble: 33 × 6 # Rowwise: Team Team `Total Respondents` Total Democr…¹ Total…² perce…³ perce…⁴ <chr> <dbl> <dbl> <dbl> <dbl> <dbl> 1 Arizona Cardinals 148 39 32 0.26 0.22 2 Atlanta Falcons 188 59 44 0.31 0.23 3 Baltimore Ravens 150 56 27 0.37 0.18 4 Buffalo Bills 92 22 16 0.24 0.17 5 Carolina Panthers 164 51 45 0.31 0.27 6 Chicago Bears 285 94 55 0.33 0.19 7 Cincinnati Bengals 106 37 32 0.35 0.3 8 Cleveland Browns 105 34 28 0.32 0.27 9 Dallas Cowboys 438 128 129 0.29 0.29 10 Denver Broncos 313 100 87 0.32 0.28 # … with 23 more rows, and abbreviated variable names ¹`Total Democrats`, # ²`Total Republicans`, ³percent_dem, ⁴percent_rep ``` ] --- count: false .panel1-swpivot-auto[ ```r nfl_percentages %>% * pivot_longer(c(percent_dem, percent_rep), * names_to = "type", * values_to = "political_percentages") ``` ] .panel2-swpivot-auto[ ``` # A tibble: 66 × 6 Team `Total Respondents` `Total Democrats` Total…¹ type polit…² <chr> <dbl> <dbl> <dbl> <chr> <dbl> 1 Arizona Cardinals 148 39 32 perc… 0.26 2 Arizona Cardinals 148 39 32 perc… 0.22 3 Atlanta Falcons 188 59 44 perc… 0.31 4 Atlanta Falcons 188 59 44 perc… 0.23 5 Baltimore Ravens 150 56 27 perc… 0.37 6 Baltimore Ravens 150 56 27 perc… 0.18 7 Buffalo Bills 92 22 16 perc… 0.24 8 Buffalo Bills 92 22 16 perc… 0.17 9 Carolina Panthers 164 51 45 perc… 0.31 10 Carolina Panthers 164 51 45 perc… 0.27 # … with 56 more rows, and abbreviated variable names ¹`Total Republicans`, # ²political_percentages ``` ] <style> .panel1-swpivot-auto { color: white; width: 56%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-swpivot-auto { color: white; width: 42%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-swpivot-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ## Give it a variable ```r nlf_percentages_long <- nfl_percentages %>% pivot_longer(c(percent_dem, percent_rep), names_to = "type", values_to = "political_percentages") ``` --- ## More Data Wrangling: Pivoting count: false .panel1-swfacet-auto[ ```r *ggplot(nlf_percentages_long, * aes(Team, * political_percentages, * fill = political_percentages)) ``` ] .panel2-swfacet-auto[ ![](Slides-Week-5R_files/figure-html/swfacet_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-swfacet-auto[ ```r ggplot(nlf_percentages_long, aes(Team, political_percentages, fill = political_percentages)) + * geom_bar(stat="identity") ``` ] .panel2-swfacet-auto[ ![](Slides-Week-5R_files/figure-html/swfacet_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-swfacet-auto[ ```r ggplot(nlf_percentages_long, aes(Team, political_percentages, fill = political_percentages)) + geom_bar(stat="identity") + * coord_flip() ``` ] .panel2-swfacet-auto[ ![](Slides-Week-5R_files/figure-html/swfacet_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-swfacet-auto[ ```r ggplot(nlf_percentages_long, aes(Team, political_percentages, fill = political_percentages)) + geom_bar(stat="identity") + coord_flip() + * theme_minimal() ``` ] .panel2-swfacet-auto[ ![](Slides-Week-5R_files/figure-html/swfacet_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-swfacet-auto[ ```r ggplot(nlf_percentages_long, aes(Team, political_percentages, fill = political_percentages)) + geom_bar(stat="identity") + coord_flip() + theme_minimal() + * facet_wrap(.~type) ``` ] .panel2-swfacet-auto[ ![](Slides-Week-5R_files/figure-html/swfacet_auto_05_output-1.png)<!-- --> ] <style> .panel1-swfacet-auto { color: white; width: 47.8604651162791%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-swfacet-auto { color: white; width: 50.1395348837209%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-swfacet-auto { color: white; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- # Your turn Try these on your own 1. Compare how the different ethnicities within each political party differ. 2. Compare how each specific ethnicity between each political party differ. 3. Which ethnicity in each political party is the most conservative? the most liberal? --- ## That's it for today!