library(duke)
library(palmerpenguins)
library(ggmosaic)
#> Loading required package: ggplot2
library(ggplot2)
library(magrittr)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
attach(penguins)This vignette aims to comprehensively demonstrate the use and
functionality of the package duke. duke is
fully integrated with the ggplot2 and allows for the
creation of Duke official branded visualizations that are color blind
friendly.
Scatter Plot - Continuous Color
plot <- ggplot(palmerpenguins::penguins, aes(x=bill_length_mm, y = bill_depth_mm)) +
geom_point(aes(color = body_mass_g)) +
labs(title = "Bill Length vs. Bill Depth", x = "Bill Length (mm)", y = "Bill Depth (mm)")
plot +
scale_duke_continuous() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing missing values (`geom_point()`).
plot +
geom_point(shape = species) +
scale_duke_continuous() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing missing values (`geom_point()`).
#> Removed 2 rows containing missing values (`geom_point()`).
plot +
scale_duke_continuous() +
theme_minimal()
#> Warning: Removed 2 rows containing missing values (`geom_point()`).
Scatter Plot - Discrete Color
plot1 <- ggplot(palmerpenguins::penguins, aes(x=bill_length_mm, y = bill_depth_mm, color = species)) +
geom_point(size =3) +
labs(title = "Bill Length vs. Bill Depth", caption = "(Colors used) \n Duke Royal Blue, Eno, Copper", x = "Bill Length (mm)", y = "Bill Depth (mm)")
#guides(fill=guide_legend(title="New Legend Title"))
ggplot(palmerpenguins::penguins, aes(x=bill_length_mm, y = bill_depth_mm)) +
geom_point(aes(color = species)) +
labs(title = "Bill Length vs. Bill Depth", subtitle = "This is the subtitle", caption = "All text is in Duke Royal Blue", x = "Bill Length (mm)", y = "Bill Depth (mm)") +
facet_wrap(~species) +
theme_duke() +
scale_duke_discrete()
#> Atkinson-Hyperlegible is not available on your system.
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
plot1 +
theme_duke() +
scale_duke_discrete()
#> Atkinson-Hyperlegible is not available on your system.
#>
#> New names:
plot1 +
scale_duke_discrete() +
theme_minimal()
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
Bar Plot
plot2 <- ggplot(palmerpenguins::penguins, aes(x=species, fill = species)) +
geom_bar() +
labs(title = "Distribution of Penguin Species", caption = "(Colors from left to right) \n Duke Royal Blue, Duke Navy Blue, Copper", x = "Species", y = "Count")
m_penguins <- penguins %>%
dplyr::filter(sex == "male")
plot2.1 <- ggplot(m_penguins, aes(x = sex, fill = sex)) +
geom_bar()
plot2 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
temp <- data.frame(ggplot_build(plot2.1)$data[[1]])
plot2 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
plot2 +
scale_duke_discrete() +
theme_minimal()
Histogram
plot3 <- ggplot2::ggplot(palmerpenguins::penguins, aes(body_mass_g)) +
geom_histogram(ggplot2::aes(fill = species), alpha = 0.8) +
labs(title = "Distribution of Penguin Body Mass", caption = "(Colors used) \n Duke Royal Blue, Duke Navy Blue, Copper", x = "Body Mass (g)", y = "Count")
plot3 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 2 rows containing non-finite values (`stat_bin()`).
plot3 +
scale_duke_discrete() +
theme_minimal()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 2 rows containing non-finite values (`stat_bin()`).
Box Plot
plot4 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(sex, body_mass_g)) +
ggplot2::geom_boxplot() +
ggplot2::labs(title = "Comparison of Body Mass By Sex", x = "Sex", y = "Body Mass (g)")
plot4 +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing non-finite values (`stat_boxplot()`).
plot4 +
theme_minimal()
#> Warning: Removed 2 rows containing non-finite values (`stat_boxplot()`).
Density Plot
plot5 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(bill_depth_mm)) +
ggplot2::geom_density(ggplot2::aes(fill = species)) +
ggplot2::labs(title = "Density of Penguin Bill Depth", x = "Bill Depth (mm)", y = "Densiy")
plot5 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing non-finite values (`stat_density()`).
plot5 +
scale_duke_discrete() +
theme_minimal()
#> Warning: Removed 2 rows containing non-finite values (`stat_density()`).
Jitter Plot - Discrete Color
plot6 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(year, body_mass_g)) +
ggplot2::geom_jitter(ggplot2::aes(color = species)) +
ggplot2::labs(title = "Comparison of Body Mass By Year", x = "Year", y = "Body Mass (g)")
plot6 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing missing values (`geom_point()`).
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
plot6 +
scale_duke_discrete() +
theme_minimal()
#> Warning: Removed 2 rows containing missing values (`geom_point()`).
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
## Jitter Plot - Discrete Color
plot6.1 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(year, body_mass_g)) +
ggplot2::geom_jitter(ggplot2::aes(color = bill_length_mm)) +
ggplot2::labs(title = "Comparison of Body Mass By Year", x = "Year", y = "Body Mass (g)")
plot6.1 +
scale_duke_continuous() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing missing values (`geom_point()`).
plot6.1 +
scale_duke_continuous() +
theme_minimal()
#> Warning: Removed 2 rows containing missing values (`geom_point()`).
Mosaic Plot
plot7 <- ggplot(data = palmerpenguins::penguins) +
ggmosaic::geom_mosaic(aes(x=ggmosaic::product(sex, island), fill = sex)) +
labs(title = "Penguin Sex vs. Island", x = "Island", y = "Penguin Sex", caption = "(Color from top to bottom) \n Granite, Duke Navy Blue, Duke Royal Blue")
plot7 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: `unite_()` was deprecated in tidyr 1.2.0.
#> ℹ Please use `unite()` instead.
#> ℹ The deprecated feature was likely used in the ggmosaic package.
#> Please report the issue at <https://github.com/haleyjeppson/ggmosaic>.
plot7 +
scale_duke_discrete() +
theme_minimal()
Label Plot
plot8 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(bill_length_mm, bill_depth_mm, fill = island)) +
ggplot2::geom_label(aes(label = island)) +
ggplot2::labs(title = "Bill Length/Depth by Island", x = "Bill Length (mm)", y = "Bill Depth (mm)")
plot8 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing missing values (`geom_label()`).
plot8 +
scale_duke_discrete() +
theme_minimal()
#> Warning: Removed 2 rows containing missing values (`geom_label()`).
Quantile Plot
plot9 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(bill_length_mm, bill_depth_mm, color = species)) +
ggplot2::geom_quantile() +
ggplot2::labs(title = "Bill Length/Depth Quantiles", x = "Bill Length (mm)", y = "Bill Depth (mm)")
plot9 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing non-finite values
#> (`stat_quantile()`).
#> Warning: Computation failed in `stat_quantile()`
#> Caused by error in `compute_group()`:
#> ! The package `quantreg` is required for `stat_quantile()`
plot9 +
scale_duke_discrete() +
theme_minimal()
#> Warning: Removed 2 rows containing non-finite values (`stat_quantile()`).
#> Computation failed in `stat_quantile()`
Area Plot
plot10 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(body_mass_g, fill = species)) +
ggplot2::geom_area(stat = "bin") +
ggplot2::labs(title = "Area of Body Mass Index", x = "BMI")
plot10 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 2 rows containing non-finite values (`stat_bin()`).
plot10 +
scale_duke_discrete() +
theme_minimal()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 2 rows containing non-finite values (`stat_bin()`).
Dot Plot
plot11 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(body_mass_g)) +
ggplot2::geom_dotplot(aes(fill=species)) +
ggplot2::labs(title = "Dotplot of BMI", x = "BMI")
plot11 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Bin width defaults to 1/30 of the range of the data. Pick better value with
#> `binwidth`.
#> Warning: Removed 2 rows containing missing values (`stat_bindot()`).
plot11 +
scale_duke_discrete() +
theme_minimal()
#> Bin width defaults to 1/30 of the range of the data. Pick better value with
#> `binwidth`.
#> Warning: Removed 2 rows containing missing values (`stat_bindot()`).
Frequency Polynomial Plot
plot12 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(body_mass_g)) +
ggplot2::geom_freqpoly(aes(color=species)) +
ggplot2::labs(title = "Frequency Polynomial Plot of BMI", x = "BMI")
plot12 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 2 rows containing non-finite values (`stat_bin()`).
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
plot12 +
scale_duke_discrete() +
theme_minimal()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 2 rows containing non-finite values (`stat_bin()`).
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
Column Plot
plot13 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(species, body_mass_g, color = species)) +
ggplot2::geom_col() +
ggplot2::labs(title = "BMI By Species of BMI", x = "Species", y = "BMI")
plot13 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing missing values (`position_stack()`).
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
plot13 +
scale_duke_discrete() +
theme_minimal()
#> Warning: Removed 2 rows containing missing values (`position_stack()`).
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
Violin Plot
plot14 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(species, body_mass_g, fill = species)) +
geom_violin(scale = "area") +
ggplot2::labs(title = "BMI By Species", x = "Species", y = "BMI")
plot14 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> Warning: Removed 2 rows containing non-finite values
#> (`stat_ydensity()`).
plot14 +
scale_duke_discrete() +
theme_minimal()
#> Warning: Removed 2 rows containing non-finite values
#> (`stat_ydensity()`).
Count Plot
plot15 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(species, island, color = species)) +
geom_count() +
ggplot2::labs(title = "Species Count by Island", x = "Species", y = "Island")
plot15 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
plot15 +
scale_duke_discrete() +
theme_minimal()
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
Step Plot
plot16 <- ggplot2::ggplot(palmerpenguins::penguins, ggplot2::aes(year, body_mass_g, color = species)) +
geom_step()
ggplot2::labs(title = "BMI By Year", x = "Year", y = "BMI")
#> $x
#> [1] "Year"
#>
#> $y
#> [1] "BMI"
#>
#> $title
#> [1] "BMI By Year"
#>
#> attr(,"class")
#> [1] "labels"
plot16 +
scale_duke_discrete() +
theme_duke()
#> Atkinson-Hyperlegible is not available on your system.
#> Warning in theme_duke(): Defaulting to sans font for title.
#> Warning in theme_duke(): Defaulting to sans font for legend.
#> Warning in theme_duke(): Defaulting to sans font for axis.
#> Warning in theme_duke(): Defaulting to sans font for caption.
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
plot16 +
scale_duke_discrete() +
theme_minimal()
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`
Coordinate Polar
plot1 +
facet_wrap(~species) +
theme_bw() +
scale_duke_discrete()
#> Warning: Removed 2 rows containing missing values (`geom_point()`).
#> New names:
#> • `colour` -> `colour...1`
#> • `colour` -> `colour...3`