Question 1

The following questions use the Marriage data set from the mosaicData package.

marriage <- Marriage

# Create an informative and meaningful data graphic.
ggplot(marriage, aes(x = college, fill = race)) + 
  geom_histogram(binwidth = 1, position = "dodge")

summary(marriage$race)
## American Indian           Black        Hispanic           White 
##               1              22               1              74
# Create a data graphic with at least five variables (either quantitative or categorical).
ggplot(data = marriage, aes(x = age, y = college)) + 
  geom_point(aes(color = sign, shape = race), size = 2) +
  facet_wrap(~person)

Question 2

Boxplot Visualization

This boxplot was built using the mpg dataset. Notice the changes in axis labels.

Question 3

Stacked Density Plot

This graphic is built with the diamonds dataset in the ggplot2 package.

Question 4

Sideways bar plot

This graphic uses the penguins dataset and shows the counts between males and females by species.

penguins <- penguins
penguins %>%
  count(sex, species) %>%
  ggplot() + 
  geom_col(aes(x = sex, y = n, fill = species)) +
  scale_fill_manual(values = c("darkorange", "purple", "cyan4")) + 
  facet_wrap(~species, ncol = 1) + 
  theme_minimal() + 
  theme(legend.position = 'none') + 
  labs(x = "Sex", y = "Count") + 
  coord_flip()

Question 5

Scatterplot

This figure examines the relationship between bill length and depth in the penguins dataset.

ggplot(data = penguins, aes(x = bill_length_mm, y = bill_depth_mm, color = species)) + 
  geom_point(aes(shape = species), size = 2) + 
  geom_smooth(method = 'lm', se = FALSE) +
  scale_color_manual(values = c("darkorange", "darkorchid", "cyan4")) + 
  labs(x = "Bill Length (mm)", y = "Bill Depth (mm)", color = "Species", shape = "Species")