Harold Nelson
3/30/2021
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.0 ✓ purrr 0.3.4
## ✓ tibble 3.0.5 ✓ dplyr 1.0.3
## ✓ tidyr 1.0.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
I’ll produce part of one of Healy’s graphs and use it as a platform to illustrate color picking.
p0 <-
election %>%
filter( st != "DC",
census == "West") %>%
ggplot(mapping = aes(x = r_points,
y = reorder(state, r_points),
color = party))
p1 <- p0 + geom_vline(xintercept = 0, color = "gray30") +
geom_point(size = 2)
Now use Healy’s party_colors with scale_color_manual() to display the graphic.
Now pick some different colors. Use the html color picker to give the democrats a green color and paint the republicans black. Note: To get pure black, set everything to 0.
Now let’s practice using named colors from Rcolor.pdf. Make the democrats dodgerblue and the republicans firebrick1.
Try some different colors.
Now let’s map color to the variable r_points. First just do the default.
p0 <-
election %>%
filter( st != "DC",
census == "West") %>%
ggplot(mapping = aes(x = r_points,
y = reorder(state, r_points),
color = r_points))
p1 <- p0 + geom_vline(xintercept = 0, color = "gray30") +
geom_point(size = 2)
p1
Now try to use a color gradient with low set to blue and high set to red.
See https://ggplot2.tidyverse.org/reference/scale_gradient.html
Try from orange to purple. Or just pick a few contrasting colors.
Try the same combination with gradient2.
Try scale_color_viridis_c() with defaults.
See https://ggplot2.tidyverse.org/reference/scale_viridis.html
Reverse the direction so that light is low and dark is high.