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

###### Question

```{r load}
#| code-fold: false
#| document: show
library(tidyverse)
library(fivethirtyeight)
```

###### Question

::: question
Use the data wrangling skills you learned in [Lab 4](lab_04_wrangling.qmd) (Hint: `filter()`) 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 `college_recent_grads`, assign the resulting data frame to a new object called `college_majors`.

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


###### Question

::: question
Use the `geom_col()` function to create a **ggplot** object called `g` that is a bar graph showing the total number of recent graduates in each `major`.
Be sure to map `major` and `total` to the `x` and `y` aesthetics, respectively, in the call to `ggplot()` (i.e., *not* in the call to `geom_col()`).
Don't worry about colors, labels, or anything else just yet.

If you're having trouble with creating an object, see [R Objects in Lab 2](https://smithcollege-sds.github.io/sds100/lab_02_problem_solving.html#r-objects).
:::


###### Question

::: question
Add a call to `geom_col()` to `g` again.
This time, map the `fill` aesthetic to the `sharewomen` variable within `geom_col()`.

Save the resulting plot as `g` (so you are overwriting the previous `g`).

Hint: Make sure you use `aes()` *inside* your call to `geom_col()`!
:::


###### Question

::: question
Using the instructions above, add `aes()` to `g` and use the `fct_reorder()` function to reset the `x` aesthetic so that the bars for `major` appear in order according to the value of `total`.
:::


###### Question

::: question
Use the `labs()` function to add a title, subtitle, and caption to `g`.
Remember to assign the output back to `g` (i.e., overwrite/update `g`).
:::



###### Question

::: question
Use `scale_fill_viridis_c()` to specify the viridis color palette for the fill color.

Also specify the `name` argument to something human-readable (e.g., `% Women`).
:::


###### Question

::: question
Use `scale_x_discrete()` to suppress the horizontal axis label by setting the `name` argument to `NULL`.
:::


###### Question

::: question
Use the `labels` argument within the `scale_y_continuous()` function to force the numbers to show in the format provided by `scales::label_comma()` (the `label_comma()` function from the **scales** package).

Also improve the axis label by setting the `name` argument to `scale_y_continuous()`.
:::


###### Question

::: question
Pass the `scales::label_wrap()` function to the `labels` argument in `scale_x_discrete()` to wrap the major field names to 25 characters.
:::


###### Question

::: question
Use the `coord_flip()` function to flip the coordinate axes.
:::


###### Question

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


