Well this is just delightful!
After you install the wesanderson package, you can
- create a ggplot2 graph object
- choose the Wes Anderson color scheme you want to use and create a palette object
- add the graph object and and the palette object and behold your beautiful data
I want to examine the breakdown of how each head of state was appointed to rule the country and the type of regime. First I’ll examine the break down in the 18th century.
To generate a vector of colors, the
wes_palette() function requires:
wes_palette(name, n, type = c("discrete", "continuous"))
name: Name of desired palette
n: Number of colors desired (i.e. how many categories. In my case, there are four regime types so n = 4).
type: Either “continuous” or “discrete”. Use continuous if you want to automatically interpolate between colors.
eighteenth_century <- data_1880s %>% filter(!is.na(regime)) %>% filter(!is.na(appointment)) %>% ggplot(aes(appointment)) + geom_bar(aes(fill = factor(regime)), position = position_stack(reverse = TRUE)) + theme(legend.position = "top", text = element_text(size=15), axis.text.x = element_text(angle = -30, vjust = 1, hjust = 0))
Both the regime variable and the appointment variable are discrete categories so we can use the geom_bar() function. When adding the palette to the barplot object, we can use the
eighteenth_century + scale_fill_manual(values = wes_palette("Darjeeling1", n = 4)
Now to compare the breakdown with countries in the 21st century (2000 to present)
The names of all the palettes you can enter into the