Grouped data (slide 14)

p <- ggplot(data = gapminder, mapping = aes(x = year, y = gdpPercap))
p + geom_line(color="gray70", aes(group = country)) +
    geom_smooth(size = 1.1, method = "lm", se = FALSE) +
    scale_y_log10(labels=scales::dollar) +
    facet_wrap(~ continent, ncol = 5) +
    labs(x = "Year",
         y = "GDP per capita",
         title = "GDP per capita on Five Continents") +
    theme_bw()

Facets (slide 19)

p <- ggplot(data = gss_sm, mapping = aes(y = degree, fill = degree))
p + geom_bar() +
   facet_grid(sex ~ race) +
   guides(fill = "none") +
   labs(y = NULL, x = "Count", title = "Degrees earned by GSS Participants")

Organ data Cleveland dotplot demo (slide 29)

by_country <- organdata |> group_by(consent_law, country) |>
                            summarize(donors_mean = mean(donors, na.rm = T),
                                      donors_sd = sd(donors, na.rm = T))
## `summarise()` has grouped output by 'consent_law'. You can override using the
## `.groups` argument.
p <- ggplot(by_country, mapping = aes(y = reorder(country, donors_mean), 
                                      x = donors_mean,
                                      color = consent_law))
p + geom_point() +
    theme(legend.position = "top") +
    labs(y = NULL, x = "Donor Procurement Rate", color = "Consent Law")

Organ data pointrange plot demo (slide 30)

p <- ggplot(by_country, mapping = aes(y = reorder(country, donors_mean), 
                                      x = donors_mean,
                                      xmin = donors_mean - donors_sd, 
                                      xmax = donors_mean + donors_sd,
                                      color = consent_law))
p + geom_pointrange() +
  theme(legend.position = "top") +
  labs(y = NULL, color = "Consent Law")