Skip to content

American Politics-Inspired (but, apolitical) Color Palette Generator

License

Notifications You must be signed in to change notification settings

pdwaggoner/amerika

Repository files navigation

amerika: An American politics-inspired color palette generator

CRAN_Status_Badge Downloads Documentation PRs Welcome

With a nod to Franz Kafka's first (and incomplete) novel, Amerika, the amerika package offers a variety of a American politics-inspired color palettes for a host of applications both in and out of politics. Building on Karthik Ram's approach to designing color palettes in the wesanderson package (with permission), amerika offers a variety of color palettes ranging from blue on the left to gray in the middle and red on the right.

Palette options range from only a few colors to several colors, but with discrete and continuous options to offer greatest flexibility to the user. amerika allows for a range of applications, from mapping brief discrete scales (e.g., three colors for Democrats, Independents, and Republicans) to continuous interpolated arrays including dozens of shades graded from blue to red (e.g., visualizing preference "feeling thermometers"). See below for a list of the palettes followed by a few political and non-political examples.

Installation

install.packages("amerika")
library(amerika)

Use

Users simply supply the name of the desired palette in the main function amerika_palette(), along with the number of colors desired from the palette (e.g., only 4 from a 5-color palette), and whether "continuous" or "discrete" type mapping is desired.

Palettes

  1. Republican: three shades of red
  2. Democrat: three shades of blue
  3. Dem_Ind_Rep3: three colors including blue, gray, and red
  4. Dem_Ind_Rep5: five colors including two shades of blue, one shade of gray, and two shades of red
  5. Dem_Ind_Rep7: seven colors including three shades of blue, one shade of gray, and three shades of red

Displaying each palette

amerika_palette("Republican")

amerika_palette("Democrat")

amerika_palette("Dem_Ind_Rep3")

amerika_palette("Dem_Ind_Rep5")

amerika_palette("Dem_Ind_Rep7")

Interpolating between existing colors based on the palettes using the "continuous" type

amerika_palette(n = 50, name = "Republican", type = "continuous")

amerika_palette(n = 50, name = "Democrat", type = "continuous")

amerika_palette(n = 50, name = "Dem_Ind_Rep3", type = "continuous")

amerika_palette(n = 50, name = "Dem_Ind_Rep5", type = "continuous")

amerika_palette(n = 50, name = "Dem_Ind_Rep7", type = "continuous")

Example Political Cases (Discrete and Continuous)

library(tidyverse)

data <- data.frame(pid = sample(1:3, 3000, replace=TRUE)) %>%
  mutate(Party = recode(pid,
                        `1` = "Democrat",
                        `2` = "Independent",
                        `3` = "Republican"))

# Discrete: "political party" on a three point scale (hypothetical, of course)
ggplot(data, aes(Party)) +
  geom_bar(fill=amerika_palette(name = "Dem_Ind_Rep3")) + 
  theme_bw()

library(tidyverse)
# Continuous: "ideology" on a 100 point scale (hypothetical for demo purposes only)
data1 <- data.frame(id = sample(1:100, 3000, replace=TRUE))

ggplot(data1, aes(id)) +
  geom_bar(fill=amerika_palette(n = 100, name = "Dem_Ind_Rep7", type = "continuous")) +
  labs(x = "Political Ideology (Liberal - Conservative)",
       y = "Count of Respondents") +
  theme_bw()

Non-Political Cases (5 and 7 level palettes)

library(tidyverse)

# 5-level (discrete) palette
ggplot(diamonds, aes(factor(cut), fill = factor(cut))) +
  geom_bar(fill=amerika_palette("Dem_Ind_Rep5")) + 
  theme_bw()

library(tidyverse)

# 7-level (discrete) palette
ggplot(diamonds, aes(factor(color), fill = factor(color))) +
  geom_bar(fill=amerika_palette("Dem_Ind_Rep7")) + 
  theme_bw()

How do I get amerika?

While the package is available for download at CRAN, amerika is stored and developed at this GitHub repository, https://github.com/pdwaggoner/amerika/, along with an issue tracker for reporting bugs as well as suggesting package extensions and/or enhancements. In the spirit of open science, I welcome any level of interaction with the package.

About

American Politics-Inspired (but, apolitical) Color Palette Generator

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages