Skip to contents

Partisan scales for ggplot2

Usage

scale_fill_party_c(
  name = "Vote share",
  midpoint = 0.5,
  limits = 0:1,
  labels = label_party_pct(),
  oob = scales::squish,
  reverse = FALSE,
  ...
)

scale_color_party_c(
  name = "Vote share",
  midpoint = 0.5,
  limits = 0:1,
  labels = label_party_pct(),
  oob = scales::squish,
  reverse = FALSE,
  ...
)

scale_fill_party_d(labels = c("Rep.", "Dem."), reverse = FALSE, ...)

scale_color_party_d(labels = c("Rep.", "Dem."), reverse = FALSE, ...)

scale_fill_party_b(
  name = "Vote share",
  midpoint = 0.5,
  limits = 0:1,
  labels = label_party_pct(),
  oob = scales::squish,
  reverse = FALSE,
  nice.breaks = FALSE,
  ...
)

scale_color_party_b(
  name = "Vote share",
  midpoint = 0.5,
  limits = 0:1,
  labels = label_party_pct(),
  oob = scales::squish,
  reverse = FALSE,
  nice.breaks = FALSE,
  ...
)

scale_colour_party_d(labels = c("Rep.", "Dem."), reverse = FALSE, ...)

scale_colour_party_c(
  name = "Vote share",
  midpoint = 0.5,
  limits = 0:1,
  labels = label_party_pct(),
  oob = scales::squish,
  reverse = FALSE,
  ...
)

scale_colour_party_b(
  name = "Vote share",
  midpoint = 0.5,
  limits = 0:1,
  labels = label_party_pct(),
  oob = scales::squish,
  reverse = FALSE,
  nice.breaks = FALSE,
  ...
)

Arguments

name

Name for scale. Default is "Vote share".

midpoint

Scale midpoint value. Default is 0.5.

limits

Lower and upper limits for scale. Default is 0:1.

labels

Function to adjust scale labels. Default is scales::percent.

oob

Function to deal with out of bounds. Default is scales::squish().

reverse

Whether to reverse red and blue.

...

Additional arguments to ggplot::scale_* functions

nice.breaks

If TRUE, attempt to place breaks at nice values instead of exactly evenly spaced between the limits.

Value

ggplot scale function

Examples

library(ggplot2)
data(oregon)

ggplot(oregon, aes(fill = ndv / (ndv + nrv))) +
    geom_sf(size = 0) +
    scale_fill_party_c(limits=c(0.3, 0.7)) +
    theme_map()


ggplot(oregon, aes(fill = ndv / (ndv + nrv))) +
    geom_sf(size = 0) +
    scale_fill_party_b() +
    theme_map()