Skip to content

Latest commit

 

History

History
152 lines (126 loc) · 5.63 KB

README.md

File metadata and controls

152 lines (126 loc) · 5.63 KB

kubrand

Codecov test coverage R-CMD-check

The goal of kubrand is to simplify theming a ggplot2 graph using KU branded colors.

Installation

The development version of the package is available from GitHub with:

# install.packages("remotes")
remotes::install_github("bvancilku/kubrand")

Example

Make a plot using the KU-branded ggplot2 theme:

library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.0.5
#> 
#> 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
library(ggplot2)
library(magrittr)
#> Warning: package 'magrittr' was built under R version 4.0.5
library(purrr)
#> Warning: package 'purrr' was built under R version 4.0.5
#> 
#> Attaching package: 'purrr'
#> The following object is masked from 'package:magrittr':
#> 
#>     set_names

library(kubrand)
#> Configuring {kubrand}
base::set.seed(2021L + 07L + 05L)
dataset <- tibble::tibble(
  val_x_true = base::seq(1, 100, by = 1)
) %>% 
  dplyr::mutate(
    val_x_measured = val_x_true + stats::rnorm(dplyr::n(), mean = 0, sd = 0.6),
    ind_treatment = purrr::rbernoulli(dplyr::n()),
    val_y_true = val_x_true * (1.1 + (1 - 0.4 * ind_treatment) * base::sin(val_x_true / 10)),
    val_y_measured = val_y_true + stats::rnorm(dplyr::n(), mean = 0, sd = 5),
    cat_treatment = base::factor(dplyr::if_else(ind_treatment, "treatment", "control"), levels = c("control", "treatment"))
  )

categorical_palette <- kubrand::ku_pal("cat2_int", reverse = TRUE)(2L)
dataset %>% 
  ggplot2::ggplot() +
  ggplot2::aes(x = val_x_measured, y = val_y_measured, color = cat_treatment, shape = cat_treatment) +
  ggplot2::geom_point(show.legend = FALSE) +
  ggplot2::xlab("x") +
  ggplot2::ylab("y") +
  kubrand::scale_color_ku("cat2_int", reverse = TRUE) +
  ggplot2::ggtitle(
    label = glue::glue("The **{kubrand::color_text(categorical_palette[[2]], 'treatment')}** attenuates oscillation relative to the **{kubrand::color_text(categorical_palette[[1]], 'control')}**"),
    subtitle = "Sometimes one needs a subtitle. This is not one of those times."
  ) +
  theme_ku()

Code of conduct

Please note that the kubrand project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Related work

This package relies on the hard work of other package maintainers as well as many good tutorials and articles. Please allow us to commend them here.

Articles

Packages

Tools