Title: | Creating a Color-Blind Friendly Duke Color Package |
Version: | 0.0.3 |
Description: | Generates visualizations with Duke’s official suite of colors in a color blind friendly way. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
Imports: | ggplot2, scales |
URL: | https://github.com/aidangildea/duke, https://aidangildea.github.io/duke/ |
BugReports: | https://github.com/aidangildea/duke/issues |
Depends: | R (≥ 2.10) |
Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0), palmerpenguins, ggmosaic, dplyr |
Config/testthat/edition: | 3 |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2023-12-15 20:44:53 UTC; aidan |
Author: | Aidan Gildea [aut, cre],
Mine Çetinkaya-Rundel
|
Maintainer: | Aidan Gildea <aidan.gildea23@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2023-12-15 21:50:16 UTC |
Duke Color Palette (Discrete) and Scales
Description
An eight-color colorblind friendly qualitative discrete palette that is based on colors on the Duke branding guidelines.
Usage
duke_pal()
Value
Character vector of Duke palette HEX codes.
References
https://brand.duke.edu/colors/
Examples
duke_pal()
Discrete scale constructor for color argument.
Description
Applies a Duke branded and accessible discrete color palette to ggplot geometric objects using color argument. It prioritizes high contrast colors aligned with Web Content Accessibility Guidelines (WCAG).
Usage
scale_duke_color_discrete(..., na.value = "#B5B5B5")
scale_duke_colour_discrete(..., na.value = "#B5B5B5")
Arguments
... |
Arguments passed on to |
na.value |
Color used for NA values |
Details
Partial code for this function can be attributed to ggthemes.
Value
a visualization with discrete duke color scale
Examples
library(ggplot2)
library(dplyr)
library(palmerpenguins)
# default
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, color = species)) +
geom_point()
# vs. with Duke scale
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, color = species)) +
geom_point() +
scale_duke_color_discrete()
# vs. with shape and Duke scale
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, shape = species, color = species)) +
geom_point() +
scale_duke_color_discrete()
# vs. with Duke scale, UK spelling
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, colour = species)) +
geom_point() +
scale_duke_colour_discrete()
# Make some species NAs to demonstrate na.value usage
penguins_with_NAs <- penguins |>
mutate(species = if_else(species == "Gentoo", NA, species))
# with default na.value
ggplot(penguins_with_NAs, aes(x = body_mass_g, color = species)) +
geom_density() +
scale_duke_color_discrete()
# with custom na.value
ggplot(penguins_with_NAs, aes(x = body_mass_g, color = species)) +
geom_density() +
scale_duke_color_discrete(na.value = "pink")
Continuous scale constructor.
Description
Applies a Duke branded and accessible continuous color scale to ggplot geometric objects. It is applicable for both fill and color arguments. Defines gradient scale from dark to light to improve visibility and contrast for readers.
Usage
scale_duke_continuous(
...,
low = "#00539B",
high = "#E2E6ED",
space = "Lab",
na.value = "#666666",
guide = "colourbar",
aesthetics = c("colour", "color", "fill")
)
Arguments
... |
Arguments passed on to continuous_scale(). |
low |
Low end of color gradient. |
high |
High end of color gradient. |
space |
Color space in which to calculate gradient. |
na.value |
Color used for NA values. |
guide |
Type of legend. "colorbar" for continuous scale, "legend" for discrete scale. |
aesthetics |
String or vector of strings detailing what aesthetic features this continuous scale can apply to. |
Value
a visualization with continuous duke color scale
Examples
library(ggplot2)
library(palmerpenguins)
# default
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, color = body_mass_g)) +
geom_point()
# vs. with Duke scale
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, color = body_mass_g)) +
geom_point() +
scale_duke_continuous()
Discrete scale constructor for fill argument.
Description
Applies a Duke branded and accessible discrete color palette to ggplot geometric objects using fill argument. It prioritizes high contrast colors aligned with Web Content Accessibility Guidelines (WCAG).
Usage
scale_duke_fill_discrete(..., na.value = "#B5B5B5")
Arguments
... |
Arguments passed on to |
na.value |
Color used for NA values |
Value
a visualization with discrete duke color scale in fill
Examples
library(ggplot2)
library(dplyr)
library(palmerpenguins)
# default
ggplot(penguins, aes(x = species, fill = species)) +
geom_bar()
# vs. with Duke scale
ggplot(penguins, aes(x = species, fill = species)) +
geom_bar() +
scale_duke_fill_discrete()
# Make some species NAs to demonstrate na.value usage
penguins_with_NAs <- penguins |>
mutate(species = if_else(species == "Gentoo", NA, species))
# with default na.value
ggplot(penguins_with_NAs, aes(x = species, fill = species)) +
geom_bar() +
scale_duke_fill_discrete()
# with custom na.value
ggplot(penguins_with_NAs, aes(x = species, fill = species)) +
geom_bar() +
scale_duke_fill_discrete(na.value = "pink")
Implements theme components.
Description
Defines the overall aesthetic and thematic features of the plot. This function specifies simple background, grid line, text, and legend arguments to create minimalist design. Its use is intended for ggplot objects.
Usage
theme_duke(
base_size = 11,
base_family = "",
base_line_size = base_size/22,
base_rect_size = base_size/22
)
Arguments
base_size |
the base size |
base_family |
the base family |
base_line_size |
the baseline size |
base_rect_size |
the base rect |
Value
a plot with Duke colors
Examples
library(ggplot2)
library(palmerpenguins)
# default
p <- ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, color = species)) +
geom_point() +
labs(
title = "Bill length and depth of penguins",
subtitle = "Dimensions for Adelie, Chinstrap, and Gentoo Penguins",
x = "Bill depth (mm)",
y = "Bill length (mm)",
color = "Species",
caption = "Source: palmerpenguins package."
)
p
# vs. with Duke theme
p +
theme_duke()
# vs. with Duke theme and scale
p +
scale_duke_color_discrete() +
theme_duke()
# with Duke theme, scale, and further customization to theme
p +
scale_duke_color_discrete() +
theme_duke() +
theme(
plot.title = element_text(color = "red", size = 20),
plot.background = element_rect(fill = "pink", color = "yellow"),
panel.grid = element_blank()
)