Skip to content

Daniel-Carpenter/styles

Repository files navigation

DBC Style Guide Usage and Examples

Daniel Carpenter


Overview


Installation of Package

# Install devtools if not installed (for GitHub Package)
if (!require("devtools"))   install.packages("devtools")

# Install the styles repository
remotes::install_github("Daniel-Carpenter/styles")

ggplot2 Integration

# Retrieve theme with helpful theme functions
library(styles)
library(ggplot2)

Create a basic plot structure

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


Use Multiple Colors

Default Color Palette

Using DBC Style

basePlot +
  
  # Use the DBC color palette
  scale_color_dbc() +
  
  # Get the DBC ggplot theme
  theme_dbc()


Override Color with Fill

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()


Use only 1 Color

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()


Colors Deep Dive

What Colors are Available?

  • Notice displayNames = TRUE, which show you what hex codes are associated with the color names.

  • Default is displayNames = FALSE for best functionality with plotting

Fill colors

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" 

Line colors

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" 

Base colors, like the ones on the navy background of slide decks

scale_dbc('base', displayNames = TRUE)
     navy     navy1     navy2 
"#3F4953" "#394149" "#2D343B" 

Text, Background, Border, and Greyed out colors

  • 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"

How to get 1 color?

# Single color from the fill palette
scale_dbc('fill', 'red')
[1] "#F6B7B4"
# Single color from the base palette
scale_dbc('base', 'navy')
[1] "#3F4953"

How to get >1 colors

# 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"


About

Daniel Carpenter's Color Styles Package for R

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages