Daniel Carpenter
- Package that streamlines color palette usage, adapated from the Tableau 10 Palette
- Leverages
ggplot2
-like functionality- See colorblind statistics for the fill palette and the color (line) palette
# Install devtools if not installed (for GitHub Package)
if (!require("devtools")) install.packages("devtools")
# Install the styles repository
remotes::install_github("Daniel-Carpenter/styles")
# Retrieve theme with helpful theme functions
library(styles)
library(ggplot2)
Does NOT include DBC Styles
basePlot <- ggplot(data = mtcars,
aes(x = wt,
shape = as.factor(cyl),
color = as.factor(cyl),
y = mpg
)
) +
geom_point(size = 5)
basePlot # Display
Using DBC Style
basePlot +
# Use the DBC color palette
scale_color_dbc() +
# Get the DBC ggplot theme
theme_dbc()
Using DBC Style
basePlot +
# Use the DBC Fill palette (override)
scale_color_manual(values = scale_dbc('fill', 3) ) +
# Get the DBC ggplot theme
theme_dbc()
Using DBC Style
basePlot +
# Use only a single color (note using line palette)
geom_point(color = scale_dbc('color', 'blue'),
size = 5) +
# Get the DBC ggplot theme
theme_dbc()
-
Notice
displayNames = TRUE
, which show you what hex codes are associated with the color names. -
Default is
displayNames = FALSE
for best functionality with plotting
scale_dbc('fill', displayNames = TRUE)
blue orange red green purple blue1 yellow grey
"#BECDE0" "#FFD597" "#F6B7B4" "#BEE0D2" "#E4C6DC" "#BDDBE1" "#F7E5B3" "#DCDADA"
pink tan
"#FCC8DA" "#E5CFC5"
scale_dbc('color', displayNames = TRUE)
blue orange red green purple blue1 yellow grey
"#6388B4" "#E68900" "#EB4B43" "#54AC88" "#B07AA1" "#3C9DAA" "#C5A952" "#8A807E"
pink tan
"#D16D91" "#945430"
scale_dbc('base', displayNames = TRUE)
navy navy1 navy2
"#3F4953" "#394149" "#2D343B"
- These are all separate since usually only selecting one
scale_dbc('text') # Text (dark gray)
[1] "#585858"
scale_dbc('background') # Background (white)
[1] "#FAFAFA"
scale_dbc('border') # Border (light gray)
[1] "#E6E6E6"
scale_dbc('grayedOut') # (Very light gray)
[1] "grey87"
# Single color from the fill palette
scale_dbc('fill', 'red')
[1] "#F6B7B4"
# Single color from the base palette
scale_dbc('base', 'navy')
[1] "#3F4953"
# Get the first 3 colors in the line palette
scale_dbc('color', 3)
[1] "#6388B4" "#E68900" "#EB4B43"
# Get the last 3 colors in the fill palette
scale_dbc('color')[6:8]
[1] "#3C9DAA" "#C5A952" "#8A807E"
# Or access specific colors all at once
scale_dbc('color', 'blue', 'orange', 'green', 'yellow')
[1] "#6388B4" "#E68900" "#54AC88" "#C5A952"