library(ggplot2)
library(dplyr)
# Categorical variable with two levels
ggplot(evals, aes(x = ethnicity, fill = ethnicity)) +
geom_bar() +
scale_fill_openintro("two")
# Categorical variable with three levels
ggplot(evals, aes(x = rank, fill = rank)) +
geom_bar() +
scale_fill_openintro("three")
# Continuous variable with levels
# Generates a palette, but may not be the best palette
# in terms of color-blind and grayscale friendliness
ggplot(diamonds, aes(x = clarity, fill = clarity)) +
geom_bar() +
scale_fill_openintro()
# For continuous palettes
# use scale_color_gradient instead
ggplot(evals, aes(
x = bty_avg, y = score,
color = score
)) +
geom_jitter(size = 2) +
scale_color_gradient(low = IMSCOL["blue", "full"], high = IMSCOL["blue", "f6"])
ggplot(evals, aes(
x = bty_avg, y = score,
color = cls_perc_eval
)) +
geom_jitter(size = 2) +
scale_color_gradient(low = IMSCOL["green", "full"], high = IMSCOL["green", "f6"])
Run the code above in your browser using DataLab