This homework is due on Mar. 7, 2024 at 11:00pm. Please submit as a pdf file on Canvas.

Problem 1: (9 pts) We will work with the dataset olympics_2002 that contains the count of all athletes by sex for the 2002 Winter Olympics in Salt Lake City. It has been derived from the olympics dataset, which is described here: https://github.com/rfordatascience/tidytuesday/blob/master/data/2021/2021-07-27/readme.md

olympics_2002
## # A tibble: 1 × 2
##       F     M
##   <int> <int>
## 1  1582  2527

Follow these steps and display the modified data frame after each step:

  1. Rearrange the data frame into long form. The resulting data frame will have two columns, which you should call sex and count, respectively. There will be two rows of data, one for female and one for male athletes.
  2. Create a new column in which you calculate the percent of male and female ahtletes.
  3. Rename the values in the column sex to “female” and “male”.
# your code here
# your code here
# your code here

Problem 2: (5 pts)

Use the color picker app from the colorspace package (colorspace::choose_color()) to create a qualitative color scale containing four colors. One of the four colors should be #A23C42, so you need to find three additional colors that go with this one. Use the function swatchplot() to plot your colors. swatchplot() takes in a vector.

# complete and uncomment
#my_colors <- c('#A23C42', ...)
#swatchplot(my_colors)

Problem 3: (6 pts)

For this problem, we will work with the midwest2 dataset (derived from midwest). In the following plot, you may notice that the axis tick labels are smaller than the axis titles, and also in a different color (gray instead of black).

  1. Use the colors you chose in Problem 1 to color the points.
  2. Make the axis tick labels the same size (size = 12) and give them the color black (color = "black")
  3. Set the entire plot background to the color "#FEF8F0". Make sure there are no white areas remaining, such as behind the plot panel or under the legend.
ggplot(midwest2, aes(popdensity, percollege, fill = state)) +
  geom_point(shape = 21, size = 3, color = "white", stroke = 0.2) +
  scale_x_log10(name = "population density") +
  scale_y_continuous(name = "percent college educated") +
  # your color choices go here in a scale function. 
  theme_classic(12) +
  theme(
    # your theme customization code goes here
  )