---
title: 'Lab 6: Polishing figures'
format:
  html:
    embed-resources: true
editor: source
knitr:
  opts_chunk:
    message: false
    fig-align: center
---

###### Question 1
```{r load}
#| code-fold: false
#| document: show
library(tidyverse)
library(fivethirtyeight)
```
###### Question 2
Use the data wrangling skills you learned in [Lab 4](lab_04_wrangling.qmd) to restrict the data set to:

1) only those majors that belong to the `major_category` values of `Computers & Mathematics` and `Engineering`, **and**
2) only those majors with at least 5,000 `total` graduates.

To avoid overwriting the original `college_recent_grads` data, assign the resulting data frame to a new object called `college_majors`.

**Hint:** the `filter()` function is your friend!

**Check:** When you're done, your new data frame should have 22 rows.

###### Question 3
Insert a new code chunk, and copy the code template below into this code chunk.
Then, fill in the three blanks to create a bar plot showing the total number of recent graduates in each of these 22 majors.
Importantly, you should:

- represent the majors along the x-axis of the plot, and the number of graduates along the y-axis of the plot.
- draw a column to represent the number of graduates in each major using the `geom_col()` function.

Don't worry about colors, labels, or anything else just yet.

###### Question 4
Display the bar plot you just created in Exercise 2 by inserting a new code chunk, and calling the `print()` function on your ggplot object.

###### Question 5
Insert a new code chunk, and copy the code template below into this code chunk.
Modify your bar plot by filling in the blank in the code template below.
Add a layer-specific aesthetic mapping that will fill in each column in the bar plot with a different color, based on the proportion of graduates in each major that are women.

###### Question 6
Generalize the example above to modify the `x` aesthetic so that the bars for each `major` appear in order according to the `total` number of recent graduates.

**Make sure to use the `<-` assignment operator to modify your ggplot object permanently!**

If you make a mistake, and your plot isn't coming out right, re-run all the code chunks prior to this exercise to start again with a clean slate.

###### Question 7
Insert a new code chunk, and copy the code template below into this code chunk.
Fill in the blanks in the code template below to add a title, subtitle, and caption to your plot.

**Make sure that the text for your plot's title, subtitle and caption is quoted!**

###### Question 8
Update your bar plot to use the viridis color palette by adding the `scale_fill_viridis_c()` function (just like you added the `labs()` function to the plot).

Use the `name` argument to for the `scale_fill_viridis_c()` function to change the name of the color legend to something more informative (e.g., "Percent Women" or "% Women").

**Make sure to use the `<-` assignment operator to modify your ggplot object permanently!**

###### Question 9
Remove your plot's x-axis label by adding the `scale_x_discrete()` function to your plot. Set the `name` argument to `NULL` to supress the axis label.

###### Question 10
Force R to use "normal" notation for the numbers along the y-axis of the plot by adding the `scale_y_continuous()` function to your plot.
Use the `labels` argument within the `scale_y_continuous()` function to force the numbers to show in the format provided by the `scales::label_comma()` function.

Also, use the `name` argument within the `scale_y_continuous()` function to improve the title for the y-axis, just like you did with the title for the color scale in Question 7.

###### Question 11
Update your plot's x-axis by using the `scale_x_discrete()` function once again.
This time, also pass the `scales::label_wrap()` function to the `labels` argument in `scale_x_discrete()`, and make sure to wrap the major field names to 25 characters.

###### Question 12
Use the `coord_flip()` function to flip the coordinate axes.

###### Question 13
Use the `facet_wrap()` function to create facets for each `major_category`.
Be sure to set the `scales` and `ncol` arguments as specified above.

