knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

pdwtheme

The goal of pdwtheme is to build out the framework for a consistent color and style theme for visualization work that I do.

Acknowledgements

Note: This is my first package:
1. A lot of it was built using the example written up by: @drsimonj (https://drsimonj.svbtle.com/creating-corporate-colour-palettes-for-ggplot2)
1. I have also been working through the R packages book as I have been working to try to figure out how to turn this into a package and is semi robust.

Installation

And the current version from GitHub with:

# install.packages("devtools")
devtools::install_github("phildwalker/pdwtheme")

# or via 
remotes::install_github("phildwalker/pdwtheme", ref = "main")

Colors used

# cols <- c(red = "#d11141", green = "#00b159", blue = "#00aedb", orange = "#f37735", yellow = "#ffc425", `light grey` = "#cccccc", `dark grey` = "#8c8c8c")

# cols <- c(`fiji green` = "#6C6F1B", black = "#171409", juniper = "#7B9192", iron = "#C8C9C9", `falu red` = "#701E1E" )
cols <- c(blue = "#18254f",  orange = "#dc572e",  `dark grey` = "#646464",  yellow = "#ef762f")

n_seq <- seq_along(cols)
image(1, n_seq, t(as.matrix(n_seq)), col = cols,
          xlab = "", ylab = "", xaxt = "n", yaxt = "n", bty = "n",
      main = "Colors used for pdw theme")
text(0.8, n_seq, names(cols), col = "white")
text(1.2, n_seq, cols, col = "white")

Example

This is a basic example which shows you how to solve a common problem:

library(pdwtheme)
library(ggplot2)

theme_set(theme_minimal())
## basic example code
# Color by discrete variable using default palette
ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
  geom_point(size = 4) +
  scale_color_pdw()

Another example of different palettes

Using the mixed palette

# Fill by discrete variable with different palette + remove legend (guide)
ggplot(mpg, aes(manufacturer, fill = manufacturer)) +
    geom_bar() +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_fill_pdw(palette = "mixed", guide = "none")

Using the main palette

# Fill by discrete variable with different palette + remove legend (guide)
ggplot(mpg, aes(manufacturer, fill = manufacturer)) +
    geom_bar() +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_fill_pdw(palette = "main", guide = "none")


phildwalker/pdwtheme documentation built on Feb. 4, 2021, 2:31 p.m.