53 Vis: Improving Graphs

Purpose: Creating a presentation-quality graph is an iterative exercise. There are many different ways to show the same data, some of which are more effective for communication than others. Let’s return to the ideas from “How Humans See Data” and use them to improve upon some graphs: This will give you practice iterating on visuals.

Reading: How Humans See Data (Video from prior exercise, for reference)

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()

53.1 Improve these graphs!

Using the ideas from the reading (video), state some issues with the following graphs. Remember the visual hierarchy:

  1. Position along a common scale
  2. Position on identical but nonaligned scales
  3. Length
  4. Angle; Slope (With slope not too close to 0, \(\pi/2\), or \(\pi\).)
  5. Area
  6. Volume; Density; Color saturation
  7. Color hue

53.1.1 q1 Use concepts from the reading to improve the following graph. Make sure your graph shows all the same variables, no more and no fewer.

## NOTE: No need to edit; run and inspect
mpg %>%
  ggplot(aes(manufacturer, cty)) +
  geom_boxplot() +
  coord_flip()

Create your improved graph here

## TODO: Create an improved version of the graph above
## NOTE: This is just one possibility
mpg %>%
  ggplot(aes(fct_reorder(manufacturer, cty), cty)) +
  geom_boxplot() +
  coord_flip()

53.1.2 q2 Use concepts from the reading to improve the following graph. Make sure your graph shows all the same variables, no more and no fewer.

## NOTE: No need to edit; run and inspect
as_tibble(mtcars) %>%
  mutate(model = rownames(mtcars)) %>%

  ggplot(aes(x = "", y = "", size = mpg)) +
  geom_point() +
  facet_wrap(~model)

Create your improved graph here

## TODO: Create an improved version of the graph above
## NOTE: This is just one possibility
as_tibble(mtcars) %>%
  mutate(
    model = rownames(mtcars),
    model = fct_reorder(model, mpg)
  ) %>%

  ggplot(aes(x = model, y = mpg)) +
  geom_col() +
  coord_flip()

53.1.3 q3 Use concepts from the reading to improve the following graph. Make sure your graph shows all the same variables, no more and no fewer.

## NOTE: No need to edit; run and inspect
diamonds %>%
  ggplot(aes(clarity, fill = cut)) +
  geom_bar()

Create your improved graph here

## TODO: Create an improved version of the graph above
## NOTE: This is just one possibility
diamonds %>%
  count(cut, clarity) %>%

  ggplot(aes(clarity, n, color = cut, group = cut)) +
  geom_line()

53.1.4 q4 Use concepts from the reading to improve the following graph. Make sure your graph shows all the same variables, no more and no fewer.

## NOTE: No need to edit; run and inspect
diamonds %>%
  ggplot(aes(x = "", fill = cut)) +
  geom_bar() +
  coord_polar("y") +
  labs(x = "")

Create your improved graph here

## TODO: Create an improved version of the graph above
## NOTE: This is just one possibility
diamonds %>%
  ggplot(aes(cut)) +
  geom_bar()