From 2852407cd82099fce2ef0089f6136a4f43808f67 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:19:44 -0500 Subject: [PATCH 01/25] exported ojo_caption functions --- NAMESPACE | 2 ++ R/ojo_labs.R | 2 ++ 2 files changed, 4 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 5891cdf..24e4a68 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,8 @@ export(geom_point) export(geom_step) export(geom_text) export(ojo_gt) +export(ojo_labs) +export(ojo_make_caption) export(okpi_blue) export(okpi_blue_light) export(okpi_blue_palette) diff --git a/R/ojo_labs.R b/R/ojo_labs.R index 4dbbca9..64d57b6 100644 --- a/R/ojo_labs.R +++ b/R/ojo_labs.R @@ -2,6 +2,7 @@ #' @description #' Creates the text for a caption to add to ggplots and gt tables, including consistent default "source: " statements. #' +#' @export #' @param source The domain / source of the data. Can be one of "oscn", "ocdc", or "ppb" for canned text, NA for no source, or a custom string. #' @param name The name of the analyst to credit ojo_make_caption <- function(analyst_name = NA, @@ -39,6 +40,7 @@ ojo_make_caption <- function(analyst_name = NA, #' @description #' Wrapper for ggplot2::labs() with consistent defaults. #' +#' @export #' @param analyst_name The name of the analyst to credit #' @param source The data source / source of the data. ojo_labs <- function (..., From 3f0c56f6fabfb82b118176aca071e596b0cb4ec3 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:27:29 -0500 Subject: [PATCH 02/25] exported functions --- R/ojo_labs.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/ojo_labs.R b/R/ojo_labs.R index 64d57b6..b4faf15 100644 --- a/R/ojo_labs.R +++ b/R/ojo_labs.R @@ -2,9 +2,10 @@ #' @description #' Creates the text for a caption to add to ggplots and gt tables, including consistent default "source: " statements. #' -#' @export #' @param source The domain / source of the data. Can be one of "oscn", "ocdc", or "ppb" for canned text, NA for no source, or a custom string. #' @param name The name of the analyst to credit +#' @returns A string with the caption text +#' @export ojo_make_caption <- function(analyst_name = NA, source = NA){ @@ -40,9 +41,9 @@ ojo_make_caption <- function(analyst_name = NA, #' @description #' Wrapper for ggplot2::labs() with consistent defaults. #' -#' @export #' @param analyst_name The name of the analyst to credit #' @param source The data source / source of the data. +#' @export ojo_labs <- function (..., analyst_name = NA, source = NA){ From 6c08a8d3068fad5e186040bd675e5f4bc383caef Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:33:47 -0500 Subject: [PATCH 03/25] fixed ojo_set_theme and made a custom ojo version of the geom_col ggproto object --- R/geoms.R | 67 +++++++++++++++++++++++++++++++++-------- R/ojo_set_theme.R | 38 ++++++++++++----------- R/scales.R | 2 +- R/theme_ojo.R | 3 +- R/theme_okpi.R | 8 +++-- man/GeomColOJO.Rd | 17 +++++++++++ man/geom_col.Rd | 21 +++++++------ man/ojo_make_caption.Rd | 3 ++ 8 files changed, 114 insertions(+), 45 deletions(-) create mode 100644 man/GeomColOJO.Rd diff --git a/R/geoms.R b/R/geoms.R index bd8f99c..56c53b3 100644 --- a/R/geoms.R +++ b/R/geoms.R @@ -1,27 +1,68 @@ -#' geom_bar in the Open Justice Oklahoma style +#' @title OJO version of the ggproto GeomCol object +#' @description +#' This is a near-exact copy of the default ggplot2 GeomCol ggproto object. +#' The only difference is that I've adjusted it to make the default column width smaller. +GeomColOJO <- ggproto("GeomCol", GeomRect, + required_aes = c("x", "y"), + + setup_data = function(data, params) { + data$width <- data$width %||% + params$width %||% (resolution(data$x, FALSE) * 0.7) # Set to 70% of resolution rather than default 90% + transform(data, + ymin = pmin(y, 0), ymax = pmax(y, 0), + xmin = x - width / 2, xmax = x + width / 2, width = NULL + ) + }, + + draw_panel = function(self, data, panel_params, coord, width = NULL) { + # Hack to ensure that width is detected as a parameter + ggproto_parent(GeomRect, self)$draw_panel(data, panel_params, coord) + } +) + +#' geom_col in the Open Justice Oklahoma style #' -#' Submit `?ggplot2::geom_line` to see the full documentation for `geom_bar()` +#' @description +#' A custom version of the geom_col() geom that uses the OJO version of the ggproto object instead of the default +#' (this makes the bars skinnier) #' #' @md -#' @param mapping mapping from ggplot2 -#' @param width bar width -#' @param ... other arguments passed to \code{geom_bar()} #' @export -geom_bar <- function(mapping = NULL, width = 0.7, ...) { - ggplot2::geom_bar(mapping = mapping, width = width, ...) +geom_col <- function(mapping = NULL, data = NULL, + position = "stack", + ..., + width = NULL, + na.rm = FALSE, + show.legend = NA, + inherit.aes = TRUE) { + + layer( + data = data, + mapping = mapping, + stat = "identity", + geom = GeomColOJO, # Use OJO version of the ggproto object instead + position = position, + show.legend = show.legend, + inherit.aes = inherit.aes, + params = list( + width = width, + na.rm = na.rm, + ... + ) + ) } -#' geom_col in the Open Justice Oklahoma style +#' geom_bar in the Open Justice Oklahoma style #' -#' Submit `?ggplot2::geom_line` to see the full documentation for `geom_col()` +#' Submit `?ggplot2::geom_line` to see the full documentation for `geom_bar()` #' #' @md #' @param mapping mapping from ggplot2 -#' @param width column width -#' @param ... other arguments passed to \code{geom_col()} +#' @param width bar width +#' @param ... other arguments passed to \code{geom_bar()} #' @export -geom_col <- function(mapping = NULL, width = 0.7, ...) { - ggplot2::geom_col(mapping = mapping, width = width, ...) +geom_bar <- function(mapping = NULL, width = 0.7, ...) { + ggplot2::geom_bar(mapping = mapping, width = width, ...) } #' geom_jitter in the Open Justice Oklahoma style diff --git a/R/ojo_set_theme.R b/R/ojo_set_theme.R index 6169a3d..555cf7c 100644 --- a/R/ojo_set_theme.R +++ b/R/ojo_set_theme.R @@ -24,23 +24,25 @@ okpi_set_theme <- function(style = "print", # set default theme to theme_ojo_*() -------------------------------------- - if (style == "print") { - ggplot2::theme_set(theme_ojo_print(base_size = base_size, - base_family = base_family, - base_line_size = base_line_size, - base_rect_size = base_rect_size)) - } else if (style == "map") { - ggplot2::theme_set(theme_ojo_map(base_size = base_size, - base_family = base_family, - base_line_size = base_line_size, - base_rect_size = base_rect_size, - scale = scale)) - } else { - stop('Invalid "style" argument. Valid styles are: ', - '"print" and "map".', - call. = FALSE - ) - } + # if (style == "print") { + ggplot2::theme_set(theme_okpi(base_size = base_size, + base_family = base_family, + base_line_size = base_line_size, + base_rect_size = base_rect_size)[[1]]) + # Need the [[1]] because theme_okpi() returns a list of [[1]] the theme, and [[2]] + [[3]] the scales + + # } else if (style == "map") { + # ggplot2::theme_set(theme_ojo_map(base_size = base_size, + # base_family = base_family, + # base_line_size = base_line_size, + # base_rect_size = base_rect_size, + # scale = scale)) + # } else { + # stop('Invalid "style" argument. Valid styles are: ', + # '"print" and "map".', + # call. = FALSE + # ) + # } # add base_family font to text and label geoms --------------------------- ggplot2::update_geom_defaults("text", list(family = base_family)) @@ -56,7 +58,7 @@ okpi_set_theme <- function(style = "print", # set default colors for monochromatic geoms ------------------------------ ggplot2::update_geom_defaults("bar", list(fill = ojothemes::okpi_blue)) - ggplot2::update_geom_defaults("col", list(fill = ojothemes::okpi_blue)) + ggplot2::update_geom_defaults("colOJO", list(fill = ojothemes::okpi_blue)) ggplot2::update_geom_defaults("point", list(colour = ojothemes::okpi_blue)) ggplot2::update_geom_defaults("line", list(colour = ojothemes::okpi_blue)) ggplot2::update_geom_defaults("step", list(colour = ojothemes::okpi_blue)) diff --git a/R/scales.R b/R/scales.R index 1bb6536..d51cfee 100644 --- a/R/scales.R +++ b/R/scales.R @@ -10,7 +10,7 @@ #' scale_color_okpi() #' @export scale_color_okpi <- function() { - scale_color_manual(values = palette_okpi_main, na.value = "green") + scale_color_manual(values = palette_okpi_main) } #' OKPI Fill Scale diff --git a/R/theme_ojo.R b/R/theme_ojo.R index 84de7ed..2cd1954 100644 --- a/R/theme_ojo.R +++ b/R/theme_ojo.R @@ -10,7 +10,8 @@ #' @param base_line_size,base_rect_size base line and rectangle sizes #' @export -theme_ojo <- function(base_size = 8.5, base_family = "Roboto Mono", +theme_ojo <- function(base_size = 14, + base_family = "Roboto Mono", base_line_size = 0.5, base_rect_size = 0.5) { diff --git a/R/theme_okpi.R b/R/theme_okpi.R index e08400c..d85cb02 100644 --- a/R/theme_okpi.R +++ b/R/theme_okpi.R @@ -7,8 +7,10 @@ #' @param base_family The font family to use; Roboto Condensed is the default. #' @param base_size The base font size to use; 14 is the default. #' @export -theme_okpi <- function(base_family = "Roboto Condensed", - base_size = 14) { +theme_okpi <- function(base_size = 14, + base_family = "Roboto Condensed", + base_line_size = base_line_size, + base_rect_size = base_rect_size) { # Base theme theme_okpi <- ggplot2::theme_grey( base_size = base_size, @@ -76,7 +78,7 @@ theme_okpi <- function(base_family = "Roboto Condensed", scale_color_okpi <- ojothemes::scale_color_okpi() scale_fill_okpi <- ojothemes::scale_fill_okpi() - # Wrap everything together in a theme + # Wrap everything together so that the scales are also applied w/ the theme list( theme_okpi, scale_color_okpi, diff --git a/man/GeomColOJO.Rd b/man/GeomColOJO.Rd new file mode 100644 index 0000000..5ae58be --- /dev/null +++ b/man/GeomColOJO.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/geoms.R +\docType{data} +\name{GeomColOJO} +\alias{GeomColOJO} +\title{OJO version of the ggproto GeomCol object} +\format{ +An object of class \code{GeomCol} (inherits from \code{GeomRect}, \code{Geom}, \code{ggproto}, \code{gg}) of length 4. +} +\usage{ +GeomColOJO +} +\description{ +This is a near-exact copy of the default ggplot2 GeomCol ggproto object. +The only difference is that I've adjusted it to make the default column width smaller. +} +\keyword{datasets} diff --git a/man/geom_col.Rd b/man/geom_col.Rd index c1f6aa6..e3da72c 100644 --- a/man/geom_col.Rd +++ b/man/geom_col.Rd @@ -4,15 +4,18 @@ \alias{geom_col} \title{geom_col in the Open Justice Oklahoma style} \usage{ -geom_col(mapping = NULL, width = 0.7, ...) -} -\arguments{ -\item{mapping}{mapping from ggplot2} - -\item{width}{column width} - -\item{...}{other arguments passed to \code{geom_col()}} +geom_col( + mapping = NULL, + data = NULL, + position = "stack", + ..., + width = NULL, + na.rm = FALSE, + show.legend = NA, + inherit.aes = TRUE +) } \description{ -Submit \code{?ggplot2::geom_line} to see the full documentation for \code{geom_col()} +A custom version of the geom_col() geom that uses the OJO version of the ggproto object instead of the default +(this makes the bars skinnier) } diff --git a/man/ojo_make_caption.Rd b/man/ojo_make_caption.Rd index 782ff45..38ed3f1 100644 --- a/man/ojo_make_caption.Rd +++ b/man/ojo_make_caption.Rd @@ -11,6 +11,9 @@ ojo_make_caption(analyst_name = NA, source = NA) \item{name}{The name of the analyst to credit} } +\value{ +A string with the caption text +} \description{ Creates the text for a caption to add to ggplots and gt tables, including consistent default "source: " statements. } From 7d625f817dc1fee77588935c08ab9fee59ff1611 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:52:52 -0500 Subject: [PATCH 04/25] everything as of our meeting to talk things over --- NAMESPACE | 2 +- R/geoms.R | 3 +- R/ojo_set_theme.R | 93 +++++++++++---------- R/theme_ojo.R | 19 +---- R/theme_okpi.R | 4 +- R/theme_tok.R | 0 man/GeomColOJO.Rd | 1 + man/geom_col.Rd | 2 +- man/{okpi_set_theme.Rd => ojo_set_theme.Rd} | 12 +-- man/theme_ojo.Rd | 2 +- man/theme_okpi.Rd | 11 ++- 11 files changed, 75 insertions(+), 74 deletions(-) create mode 100644 R/theme_tok.R rename man/{okpi_set_theme.Rd => ojo_set_theme.Rd} (79%) diff --git a/NAMESPACE b/NAMESPACE index 24e4a68..f7e088b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,13 +11,13 @@ export(geom_text) export(ojo_gt) export(ojo_labs) export(ojo_make_caption) +export(ojo_set_theme) export(okpi_blue) export(okpi_blue_light) export(okpi_blue_palette) export(okpi_red) export(okpi_red_light) export(okpi_red_palette) -export(okpi_set_theme) export(okpi_yellow) export(okpi_yellow_light) export(okpi_yellow_palette) diff --git a/R/geoms.R b/R/geoms.R index 56c53b3..d3c7dae 100644 --- a/R/geoms.R +++ b/R/geoms.R @@ -2,6 +2,7 @@ #' @description #' This is a near-exact copy of the default ggplot2 GeomCol ggproto object. #' The only difference is that I've adjusted it to make the default column width smaller. +#' This ensures that it looks right no matter what the scale of the data you're using GeomColOJO <- ggproto("GeomCol", GeomRect, required_aes = c("x", "y"), @@ -24,7 +25,7 @@ GeomColOJO <- ggproto("GeomCol", GeomRect, #' #' @description #' A custom version of the geom_col() geom that uses the OJO version of the ggproto object instead of the default -#' (this makes the bars skinnier) +#' (this makes the bars skinnier and nice looking consistently) #' #' @md #' @export diff --git a/R/ojo_set_theme.R b/R/ojo_set_theme.R index 555cf7c..e86bed8 100644 --- a/R/ojo_set_theme.R +++ b/R/ojo_set_theme.R @@ -1,9 +1,9 @@ -#' The Oklahoma Policy Institute [ggplot2] theme +#' Use Oklahoma Policy Institute [ggplot2] themes #' #' \code{ojo_set_theme} provides a [ggplot2] theme formatted according to the #' Oklahoma Policy Institute style guide, with sensible defaults. #' -#' @param style The default theme style for the R session. "print" or "map". +#' @param theme The theme you wish to use. Options are "okpi", "ojo", or "tok". #' @param base_size The base font size for the theme. All fonts are relative to #' this value. #' @param base_family The base font family for the theme. @@ -15,34 +15,41 @@ #' #' @md #' @export -okpi_set_theme <- function(style = "print", - base_size = 14, - base_family = "Roboto Condensed", - base_line_size = 0.5, - base_rect_size = 0.5, - scale = "continuous") { +ojo_set_theme <- function(theme = "okpi", + base_size = 14, + base_family = "Roboto Condensed", + base_line_size = 0.5, + base_rect_size = 0.5, + scale = "continuous") { - # set default theme to theme_ojo_*() -------------------------------------- + list_themes <- c("okpi", "ojo", "tok") + rlang::arg_match(theme, list_themes) - # if (style == "print") { - ggplot2::theme_set(theme_okpi(base_size = base_size, - base_family = base_family, - base_line_size = base_line_size, - base_rect_size = base_rect_size)[[1]]) - # Need the [[1]] because theme_okpi() returns a list of [[1]] the theme, and [[2]] + [[3]] the scales + if(theme == "okpi"){ + ggplot2::theme_set(theme_okpi(base_size = base_size, + base_family = base_family, + base_line_size = base_line_size, + base_rect_size = base_rect_size)[[1]]) # Need the [[1]] because theme_okpi() returns a list of [[1]] the theme, and [[2]] + [[3]] the scales - # } else if (style == "map") { - # ggplot2::theme_set(theme_ojo_map(base_size = base_size, - # base_family = base_family, - # base_line_size = base_line_size, - # base_rect_size = base_rect_size, - # scale = scale)) - # } else { - # stop('Invalid "style" argument. Valid styles are: ', - # '"print" and "map".', - # call. = FALSE - # ) - # } + default_color <- ojothemes::okpi_blue + + } else if (theme == "ojo") { + ggplot2::theme_set(theme_ojo(base_size = base_size, + base_family = base_family, + base_line_size = base_line_size, + base_rect_size = base_rect_size)[[1]]) + + default_color <- "black" + + } else if (theme == "tok") { + ggplot2::theme_set(theme_tok(base_size = base_size, + base_family = base_family, + base_line_size = base_line_size, + base_rect_size = base_rect_size)[[1]]) + + default_color <- "#407fc1" + + } # add base_family font to text and label geoms --------------------------- ggplot2::update_geom_defaults("text", list(family = base_family)) @@ -50,27 +57,29 @@ okpi_set_theme <- function(style = "print", ggplot2::update_geom_defaults("text_repel", list(family = base_family)) ggplot2::update_geom_defaults("label_repel", list(family = base_family)) - # set default color scales for continuous variables ----------------------- + # set default color scales for ------------------------------------------- options( ggplot2.continuous.colour = "gradient", - ggplot2.continuous.fill = "gradient" + ggplot2.continuous.fill = "gradient", + ggplot2.discrete.fill = ojothemes::palette_okpi_main, + ggplot2.discrete.colour = ojothemes::palette_okpi_main ) # set default colors for monochromatic geoms ------------------------------ - ggplot2::update_geom_defaults("bar", list(fill = ojothemes::okpi_blue)) - ggplot2::update_geom_defaults("colOJO", list(fill = ojothemes::okpi_blue)) - ggplot2::update_geom_defaults("point", list(colour = ojothemes::okpi_blue)) - ggplot2::update_geom_defaults("line", list(colour = ojothemes::okpi_blue)) - ggplot2::update_geom_defaults("step", list(colour = ojothemes::okpi_blue)) - ggplot2::update_geom_defaults("path", list(colour = ojothemes::okpi_blue)) - ggplot2::update_geom_defaults("boxplot", list(fill = ojothemes::okpi_blue)) - ggplot2::update_geom_defaults("density", list(fill = ojothemes::okpi_blue)) - ggplot2::update_geom_defaults("violin", list(fill = ojothemes::okpi_blue)) + ggplot2::update_geom_defaults("bar", list(fill = default_color)) + ggplot2::update_geom_defaults("colOJO", list(fill = default_color)) + ggplot2::update_geom_defaults("point", list(colour = default_color)) + ggplot2::update_geom_defaults("line", list(colour = default_color)) + ggplot2::update_geom_defaults("step", list(colour = default_color)) + ggplot2::update_geom_defaults("path", list(colour = default_color)) + ggplot2::update_geom_defaults("boxplot", list(fill = default_color)) + ggplot2::update_geom_defaults("density", list(fill = default_color)) + ggplot2::update_geom_defaults("violin", list(fill = default_color)) # set default colors for monochromatic stats ------------------------------ - ggplot2::update_stat_defaults("count", list(fill = ojothemes::okpi_blue)) - ggplot2::update_stat_defaults("boxplot", list(fill = ojothemes::okpi_blue)) - ggplot2::update_stat_defaults("density", list(fill = ojothemes::okpi_blue)) - ggplot2::update_stat_defaults("ydensity", list(fill = ojothemes::okpi_blue)) + ggplot2::update_stat_defaults("count", list(fill = default_color)) + ggplot2::update_stat_defaults("boxplot", list(fill = default_color)) + ggplot2::update_stat_defaults("density", list(fill = default_color)) + ggplot2::update_stat_defaults("ydensity", list(fill = default_color)) } diff --git a/R/theme_ojo.R b/R/theme_ojo.R index 2cd1954..b40eea8 100644 --- a/R/theme_ojo.R +++ b/R/theme_ojo.R @@ -18,9 +18,6 @@ theme_ojo <- function(base_size = 14, half_line <- base_size / 2L ggplot2::theme( - - # main attributes - line = ggplot2::element_line(colour = "#000000", size = base_line_size, linetype = 1L, @@ -39,9 +36,7 @@ theme_ojo <- function(base_size = 14, lineheight = 0.9, margin = ggplot2::margin(), debug = FALSE), - # Plot Attributes - plot.tag = ggplot2::element_text(size = base_size * 1.5, hjust = 0L, vjust = 0L, @@ -69,9 +64,7 @@ theme_ojo <- function(base_size = 14, r = base_line_size * 24, b = half_line, l = half_line), - # axis attributes - axis.text = ggplot2::element_text(size = base_size), axis.text.x = ggplot2::element_text(vjust = 1, margin = ggplot2::margin(t = 4L)), axis.text.y = ggplot2::element_text(hjust = 1), @@ -106,9 +99,7 @@ theme_ojo <- function(base_size = 14, linetype = NULL, lineend = NULL), axis.line.y = ggplot2::element_blank(), - # legend attributes - legend.background = ggplot2::element_blank(), legend.spacing = ggplot2::unit(20L, "pt"), @@ -135,9 +126,7 @@ theme_ojo <- function(base_size = 14, legend.box.margin = NULL, legend.box.background = NULL, legend.box.spacing = NULL, - # panel attributes - panel.background = ggplot2::element_blank(), panel.border = ggplot2::element_blank(), panel.ontop = FALSE, @@ -153,9 +142,7 @@ theme_ojo <- function(base_size = 14, panel.grid.minor = ggplot2::element_line(), panel.grid.minor.x = ggplot2::element_blank(), panel.grid.minor.y = ggplot2::element_blank(), - # strip attributes (Faceting) - strip.background = ggplot2::element_rect(fill = "#dedddd", colour = NA, size = 10L), @@ -166,16 +153,14 @@ theme_ojo <- function(base_size = 14, strip.text.x = ggplot2::element_text(margin = ggplot2::margin(t = 4.5, b = 4.5)), strip.text.y = ggplot2::element_text(angle = -90L, margin = ggplot2::margin(l = 4.5, r = 4.5)), - strip.placement = "inside", strip.placement.x = NULL, strip.placement.y = NULL, - strip.switch.pad.grid = ggplot2::unit(0.1, "cm"), strip.switch.pad.wrap = ggplot2::unit(0.1, "cm"), - # create a complete format complete = TRUE - ) + + } diff --git a/R/theme_okpi.R b/R/theme_okpi.R index d85cb02..73edcc7 100644 --- a/R/theme_okpi.R +++ b/R/theme_okpi.R @@ -9,8 +9,8 @@ #' @export theme_okpi <- function(base_size = 14, base_family = "Roboto Condensed", - base_line_size = base_line_size, - base_rect_size = base_rect_size) { + base_line_size = 0.5, + base_rect_size = 0.5) { # Base theme theme_okpi <- ggplot2::theme_grey( base_size = base_size, diff --git a/R/theme_tok.R b/R/theme_tok.R new file mode 100644 index 0000000..e69de29 diff --git a/man/GeomColOJO.Rd b/man/GeomColOJO.Rd index 5ae58be..0b8f511 100644 --- a/man/GeomColOJO.Rd +++ b/man/GeomColOJO.Rd @@ -13,5 +13,6 @@ GeomColOJO \description{ This is a near-exact copy of the default ggplot2 GeomCol ggproto object. The only difference is that I've adjusted it to make the default column width smaller. +This ensures that it looks right no matter what the scale of the data you're using } \keyword{datasets} diff --git a/man/geom_col.Rd b/man/geom_col.Rd index e3da72c..a62d79e 100644 --- a/man/geom_col.Rd +++ b/man/geom_col.Rd @@ -17,5 +17,5 @@ geom_col( } \description{ A custom version of the geom_col() geom that uses the OJO version of the ggproto object instead of the default -(this makes the bars skinnier) +(this makes the bars skinnier and nice looking consistently) } diff --git a/man/okpi_set_theme.Rd b/man/ojo_set_theme.Rd similarity index 79% rename from man/okpi_set_theme.Rd rename to man/ojo_set_theme.Rd index 40ff5f0..94c695a 100644 --- a/man/okpi_set_theme.Rd +++ b/man/ojo_set_theme.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/ojo_set_theme.R -\name{okpi_set_theme} -\alias{okpi_set_theme} -\title{The Oklahoma Policy Institute \link{ggplot2} theme} +\name{ojo_set_theme} +\alias{ojo_set_theme} +\title{Use Oklahoma Policy Institute \link{ggplot2} themes} \usage{ -okpi_set_theme( - style = "print", +ojo_set_theme( + theme = "okpi", base_size = 14, base_family = "Roboto Condensed", base_line_size = 0.5, @@ -14,7 +14,7 @@ okpi_set_theme( ) } \arguments{ -\item{style}{The default theme style for the R session. "print" or "map".} +\item{theme}{The theme you wish to use. Options are "okpi", "ojo", or "tok".} \item{base_size}{The base font size for the theme. All fonts are relative to this value.} diff --git a/man/theme_ojo.Rd b/man/theme_ojo.Rd index 63d6ac9..3106bbf 100644 --- a/man/theme_ojo.Rd +++ b/man/theme_ojo.Rd @@ -5,7 +5,7 @@ \title{A \link{ggplot2} theme formatted in the Open Justice Oklahoma style} \usage{ theme_ojo( - base_size = 8.5, + base_size = 14, base_family = "Roboto Mono", base_line_size = 0.5, base_rect_size = 0.5 diff --git a/man/theme_okpi.Rd b/man/theme_okpi.Rd index 5b8a717..698ebd6 100644 --- a/man/theme_okpi.Rd +++ b/man/theme_okpi.Rd @@ -4,12 +4,17 @@ \alias{theme_okpi} \title{A \link{ggplot2} theme formatted in the Oklahoma Policy Institute style} \usage{ -theme_okpi(base_family = "Roboto Condensed", base_size = 14) +theme_okpi( + base_size = 14, + base_family = "Roboto Condensed", + base_line_size = 0.5, + base_rect_size = 0.5 +) } \arguments{ -\item{base_family}{The font family to use; Roboto Condensed is the default.} - \item{base_size}{The base font size to use; 14 is the default.} + +\item{base_family}{The font family to use; Roboto Condensed is the default.} } \description{ \code{theme_okpi} provides a \link{ggplot2} theme formatted according to the From 2d3e20f6d1934d85ae800fa152ab63bf6b009112 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:27:08 -0500 Subject: [PATCH 05/25] moved theme_okpi into a _base and full version, tweaking defaults --- NAMESPACE | 1 + R/geoms.R | 14 ++-- R/ojo_set_theme.R | 29 +++++--- R/theme_ojo.R | 1 - R/theme_okpi.R | 161 +++++++++++++++++++++++++---------------- man/GeomColOJO.Rd | 2 +- man/geom_bar.Rd | 2 +- man/geom_col.Rd | 1 - man/geom_jitter.Rd | 2 +- man/geom_line.Rd | 4 +- man/theme_okpi.Rd | 7 +- man/theme_okpi_base.Rd | 26 +++++++ 12 files changed, 159 insertions(+), 91 deletions(-) create mode 100644 man/theme_okpi_base.Rd diff --git a/NAMESPACE b/NAMESPACE index f7e088b..8bc0f01 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -39,5 +39,6 @@ export(scale_fill_ojo) export(scale_fill_okpi) export(theme_ojo) export(theme_okpi) +export(theme_okpi_base) import(extrafont) import(ggrepel) diff --git a/R/geoms.R b/R/geoms.R index d3c7dae..45476c1 100644 --- a/R/geoms.R +++ b/R/geoms.R @@ -2,7 +2,7 @@ #' @description #' This is a near-exact copy of the default ggplot2 GeomCol ggproto object. #' The only difference is that I've adjusted it to make the default column width smaller. -#' This ensures that it looks right no matter what the scale of the data you're using +#' This ensures that it looks right no matter what the scale of the data you're using. GeomColOJO <- ggproto("GeomCol", GeomRect, required_aes = c("x", "y"), @@ -32,7 +32,6 @@ GeomColOJO <- ggproto("GeomCol", GeomRect, geom_col <- function(mapping = NULL, data = NULL, position = "stack", ..., - width = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { @@ -46,7 +45,6 @@ geom_col <- function(mapping = NULL, data = NULL, show.legend = show.legend, inherit.aes = inherit.aes, params = list( - width = width, na.rm = na.rm, ... ) @@ -55,7 +53,7 @@ geom_col <- function(mapping = NULL, data = NULL, #' geom_bar in the Open Justice Oklahoma style #' -#' Submit `?ggplot2::geom_line` to see the full documentation for `geom_bar()` +#' #' #' Submit `?ggplot2::geom_bar` to see the full documentation for `geom_bar()` #' #' @md #' @param mapping mapping from ggplot2 @@ -68,7 +66,7 @@ geom_bar <- function(mapping = NULL, width = 0.7, ...) { #' geom_jitter in the Open Justice Oklahoma style #' -#' Submit `?ggplot2::geom_jitter` to see the full documentation for `geom_jitter()` +#' #' Submit `?ggplot2::geom_jitter` to see the full documentation for `geom_jitter()` #' #' @md #' @param mapping mapping from ggplot2 @@ -85,11 +83,11 @@ geom_jitter <- function(mapping = NULL, size = 3, ...) { #' #' @md #' @param mapping mapping from ggplot2 -#' @param size line size +#' @param linewidth line size #' @param ... other arguments passed to \code{geom_line()} #' @export -geom_line <- function(mapping = NULL, size = 1, ...) { - ggplot2::geom_line(mapping = mapping, size = size, ...) +geom_line <- function(mapping = NULL, linewidth = 1.5, ...) { + ggplot2::geom_line(mapping = mapping, linewidth = linewidth, ...) } #' geom_step in the Open Justice Oklahoma style diff --git a/R/ojo_set_theme.R b/R/ojo_set_theme.R index e86bed8..ca011ee 100644 --- a/R/ojo_set_theme.R +++ b/R/ojo_set_theme.R @@ -17,7 +17,6 @@ #' @export ojo_set_theme <- function(theme = "okpi", base_size = 14, - base_family = "Roboto Condensed", base_line_size = 0.5, base_rect_size = 0.5, scale = "continuous") { @@ -26,28 +25,32 @@ ojo_set_theme <- function(theme = "okpi", rlang::arg_match(theme, list_themes) if(theme == "okpi"){ - ggplot2::theme_set(theme_okpi(base_size = base_size, - base_family = base_family, - base_line_size = base_line_size, - base_rect_size = base_rect_size)[[1]]) # Need the [[1]] because theme_okpi() returns a list of [[1]] the theme, and [[2]] + [[3]] the scales + ggplot2::theme_set(theme_okpi_base(base_size = base_size, + base_line_size = base_line_size, + base_rect_size = base_rect_size)) + base_family <- "Roboto Condensed" default_color <- ojothemes::okpi_blue + default_palette <- ojothemes::palette_okpi_main } else if (theme == "ojo") { ggplot2::theme_set(theme_ojo(base_size = base_size, - base_family = base_family, base_line_size = base_line_size, - base_rect_size = base_rect_size)[[1]]) + base_rect_size = base_rect_size)) + base_family <- "Roboto Mono" default_color <- "black" + default_palette <- ojothemes::palette_ojo_main } else if (theme == "tok") { ggplot2::theme_set(theme_tok(base_size = base_size, - base_family = base_family, + base_family = "Roboto Condensed", base_line_size = base_line_size, - base_rect_size = base_rect_size)[[1]]) + base_rect_size = base_rect_size)) + base_family <- "Roboto Condensed" default_color <- "#407fc1" + default_palette <- ojothemes::palette_okpi_main } @@ -57,16 +60,18 @@ ojo_set_theme <- function(theme = "okpi", ggplot2::update_geom_defaults("text_repel", list(family = base_family)) ggplot2::update_geom_defaults("label_repel", list(family = base_family)) - # set default color scales for ------------------------------------------- + # set default color scales ---------------------------------------------- options( ggplot2.continuous.colour = "gradient", ggplot2.continuous.fill = "gradient", - ggplot2.discrete.fill = ojothemes::palette_okpi_main, - ggplot2.discrete.colour = ojothemes::palette_okpi_main + # Set default fill / color scales to match the theme + ggplot2.discrete.fill = default_palette, + ggplot2.discrete.colour = default_palette ) # set default colors for monochromatic geoms ------------------------------ ggplot2::update_geom_defaults("bar", list(fill = default_color)) + # Update the default color for the OJO version of geom_col() ggplot2::update_geom_defaults("colOJO", list(fill = default_color)) ggplot2::update_geom_defaults("point", list(colour = default_color)) ggplot2::update_geom_defaults("line", list(colour = default_color)) diff --git a/R/theme_ojo.R b/R/theme_ojo.R index b40eea8..dde354c 100644 --- a/R/theme_ojo.R +++ b/R/theme_ojo.R @@ -9,7 +9,6 @@ #' @param base_family,base_size base font family and size #' @param base_line_size,base_rect_size base line and rectangle sizes #' @export - theme_ojo <- function(base_size = 14, base_family = "Roboto Mono", base_line_size = 0.5, diff --git a/R/theme_okpi.R b/R/theme_okpi.R index 73edcc7..0c139ae 100644 --- a/R/theme_okpi.R +++ b/R/theme_okpi.R @@ -6,73 +6,108 @@ #' @md #' @param base_family The font family to use; Roboto Condensed is the default. #' @param base_size The base font size to use; 14 is the default. +#' @param base_line_size The base line size to use; 0.5 is the default. +#' @param base_rect_size The base rect size to use; 0.5 is the default. +#' @export +theme_okpi_base <- function(base_size = 14, + base_family = "Roboto Condensed", + base_line_size = 0.5, + base_rect_size = 0.5) { + + ggplot2::theme( + line = ggplot2::element_line(colour = "#333333", + size = base_line_size, + linetype = 1L, + lineend = "butt"), + rect = ggplot2::element_rect(fill = "#ffffff", + colour = NA, + size = base_rect_size, + linetype = 1L), + text = ggplot2::element_text(family = base_family, + face = "plain", + colour = "#333333", + size = base_size, + angle = 0, + lineheight = 0.9, + margin = ggplot2::margin(), + debug = FALSE), + panel.background = ggplot2::element_blank(), + plot.background = ggplot2::element_blank(), + legend.background = ggplot2::element_rect(fill = "transparent", colour = NA), + legend.key = ggplot2::element_rect(fill = "transparent", colour = NA), + legend.position = "top", + panel.border = ggplot2::element_blank(), + panel.grid.major.x = ggplot2::element_blank(), + panel.grid.minor.x = ggplot2::element_blank(), + panel.grid.major.y = ggplot2::element_line(linewidth = 0.5), + panel.grid.minor.y = ggplot2::element_line(linewidth = 0.25), + panel.spacing = grid::unit(6, "pt"), + plot.title = ggplot2::element_text( + size = ggplot2::rel(1.66), + face = "bold", + color = palette_okpi_main[3], + lineheight = 0.7, + hjust = 0, + margin = ggplot2::margin(0, 0, 6, 0, "pt") + ), + plot.title.position = "plot", + plot.subtitle = ggplot2::element_text( + size = ggplot2::rel(1.33), + face = "bold.italic", + family = "Roboto Condensed", + lineheight = 0.7, + hjust = 0, + margin = ggplot2::margin(0, 0, 6, 0, "pt") + ), + plot.caption.position = "plot", + plot.caption = ggplot2::element_text( + size = ggplot2::rel(1), + lineheight = 0.75, + face = "italic", + ), + legend.title = ggplot2::element_blank(), + legend.text = ggplot2::element_text(size = ggplot2::rel(1.16)), + legend.margin = ggplot2::margin(0, 0, 0, 0), + axis.title = ggplot2::element_text( + size = ggplot2::rel(1.16), + face = "bold" + ), + axis.text = ggplot2::element_text( + size = ggplot2::rel(1.16) + ), + axis.line.x.bottom = ggplot2::element_line( + color = "#333333", + ), + axis.ticks = ggplot2::element_line( + color = "#333333", + ), + axis.ticks.y = ggplot2::element_blank(), + strip.background = ggplot2::element_blank(), + strip.text = ggplot2::element_text(face = "bold") + ) +} + +#' A [ggplot2] theme formatted in the Oklahoma Policy Institute style +#' +#' \code{theme_okpi} provides a [ggplot2] theme formatted according to the +#' Oklahoma Policy Institute style guide for web, with sensible defaults, +#' and also inclusdes the OKPI fill and color scales. +#' +#' @md +#' @param base_family The font family to use; Roboto Condensed is the default. +#' @param base_size The base font size to use; 14 is the default. +#' @param base_line_size The base line size to use; 0.5 is the default. +#' @param base_rect_size The base rect size to use; 0.5 is the default. #' @export theme_okpi <- function(base_size = 14, base_family = "Roboto Condensed", base_line_size = 0.5, base_rect_size = 0.5) { - # Base theme - theme_okpi <- ggplot2::theme_grey( - base_size = base_size, - base_family = base_family - ) + - # OKPI customizations - ggplot2::theme( - panel.background = ggplot2::element_blank(), - plot.background = ggplot2::element_blank(), - legend.background = ggplot2::element_rect(fill = "transparent", colour = NA), - legend.key = ggplot2::element_rect(fill = "transparent", colour = NA), - legend.position = "top", - text = ggplot2::element_text( - color = "#333333" - ), - panel.border = ggplot2::element_blank(), - panel.grid.major.x = ggplot2::element_blank(), - panel.grid.minor.x = ggplot2::element_blank(), - panel.grid.major.y = ggplot2::element_line(linewidth = 0.5), - panel.grid.minor.y = ggplot2::element_line(linewidth = 0.25), - panel.spacing = grid::unit(6, "pt"), - plot.title = ggplot2::element_text( - size = ggplot2::rel(1.66), - face = "bold", - color = palette_okpi_main[3], - lineheight = 0.7, - margin = ggplot2::margin(0, 0, 6, 0, "pt") - ), - plot.title.position = "plot", - plot.subtitle = ggplot2::element_text( - size = ggplot2::rel(1.33), - face = "bold.italic", - family = "Roboto Condensed", - lineheight = 0.7, - margin = ggplot2::margin(0, 0, 6, 0, "pt") - ), - plot.caption.position = "plot", - plot.caption = ggplot2::element_text( - size = ggplot2::rel(1), - lineheight = 0.75, - face = "italic", - ), - legend.title = ggplot2::element_blank(), - legend.text = ggplot2::element_text(size = ggplot2::rel(1.16)), - legend.margin = ggplot2::margin(0, 0, 0, 0), - axis.title = ggplot2::element_text( - size = ggplot2::rel(1.16), - face = "bold" - ), - axis.text = ggplot2::element_text( - size = ggplot2::rel(1.16) - ), - axis.line.x.bottom = ggplot2::element_line( - color = "#333333", - ), - axis.ticks = ggplot2::element_line( - color = "#333333", - ), - axis.ticks.y = ggplot2::element_blank(), - strip.background = ggplot2::element_blank(), - strip.text = ggplot2::element_text(face = "bold") - ) + + theme_okpi_base <- theme_okpi_base(base_size = base_size, + base_family = base_family, + base_line_size = base_line_size, + base_rect_size = base_rect_size) # Set scales to use okpi palettes scale_color_okpi <- ojothemes::scale_color_okpi() @@ -80,7 +115,7 @@ theme_okpi <- function(base_size = 14, # Wrap everything together so that the scales are also applied w/ the theme list( - theme_okpi, + theme_okpi_base, scale_color_okpi, scale_fill_okpi ) diff --git a/man/GeomColOJO.Rd b/man/GeomColOJO.Rd index 0b8f511..c421ce2 100644 --- a/man/GeomColOJO.Rd +++ b/man/GeomColOJO.Rd @@ -13,6 +13,6 @@ GeomColOJO \description{ This is a near-exact copy of the default ggplot2 GeomCol ggproto object. The only difference is that I've adjusted it to make the default column width smaller. -This ensures that it looks right no matter what the scale of the data you're using +This ensures that it looks right no matter what the scale of the data you're using. } \keyword{datasets} diff --git a/man/geom_bar.Rd b/man/geom_bar.Rd index b02cbf7..6681c0b 100644 --- a/man/geom_bar.Rd +++ b/man/geom_bar.Rd @@ -14,5 +14,5 @@ geom_bar(mapping = NULL, width = 0.7, ...) \item{...}{other arguments passed to \code{geom_bar()}} } \description{ -Submit \code{?ggplot2::geom_line} to see the full documentation for \code{geom_bar()} +#' #' Submit \code{?ggplot2::geom_bar} to see the full documentation for \code{geom_bar()} } diff --git a/man/geom_col.Rd b/man/geom_col.Rd index a62d79e..f4a9030 100644 --- a/man/geom_col.Rd +++ b/man/geom_col.Rd @@ -9,7 +9,6 @@ geom_col( data = NULL, position = "stack", ..., - width = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE diff --git a/man/geom_jitter.Rd b/man/geom_jitter.Rd index b37f8e3..d4d62d0 100644 --- a/man/geom_jitter.Rd +++ b/man/geom_jitter.Rd @@ -14,5 +14,5 @@ geom_jitter(mapping = NULL, size = 3, ...) \item{...}{other arguments passed to \code{geom_jitter()}} } \description{ -Submit \code{?ggplot2::geom_jitter} to see the full documentation for \code{geom_jitter()} +#' Submit \code{?ggplot2::geom_jitter} to see the full documentation for \code{geom_jitter()} } diff --git a/man/geom_line.Rd b/man/geom_line.Rd index a683781..fbac4f6 100644 --- a/man/geom_line.Rd +++ b/man/geom_line.Rd @@ -4,12 +4,12 @@ \alias{geom_line} \title{geom_line in the Open Justice Oklahoma style} \usage{ -geom_line(mapping = NULL, size = 1, ...) +geom_line(mapping = NULL, linewidth = 1.5, ...) } \arguments{ \item{mapping}{mapping from ggplot2} -\item{size}{line size} +\item{linewidth}{line size} \item{...}{other arguments passed to \code{geom_line()}} } diff --git a/man/theme_okpi.Rd b/man/theme_okpi.Rd index 698ebd6..5c48d11 100644 --- a/man/theme_okpi.Rd +++ b/man/theme_okpi.Rd @@ -15,8 +15,13 @@ theme_okpi( \item{base_size}{The base font size to use; 14 is the default.} \item{base_family}{The font family to use; Roboto Condensed is the default.} + +\item{base_line_size}{The base line size to use; 0.5 is the default.} + +\item{base_rect_size}{The base rect size to use; 0.5 is the default.} } \description{ \code{theme_okpi} provides a \link{ggplot2} theme formatted according to the -Oklahoma Policy Institute style guide for web, with sensible defaults. +Oklahoma Policy Institute style guide for web, with sensible defaults, +and also inclusdes the OKPI fill and color scales. } diff --git a/man/theme_okpi_base.Rd b/man/theme_okpi_base.Rd new file mode 100644 index 0000000..af514cd --- /dev/null +++ b/man/theme_okpi_base.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/theme_okpi.R +\name{theme_okpi_base} +\alias{theme_okpi_base} +\title{A \link{ggplot2} theme formatted in the Oklahoma Policy Institute style} +\usage{ +theme_okpi_base( + base_size = 14, + base_family = "Roboto Condensed", + base_line_size = 0.5, + base_rect_size = 0.5 +) +} +\arguments{ +\item{base_size}{The base font size to use; 14 is the default.} + +\item{base_family}{The font family to use; Roboto Condensed is the default.} + +\item{base_line_size}{The base line size to use; 0.5 is the default.} + +\item{base_rect_size}{The base rect size to use; 0.5 is the default.} +} +\description{ +\code{theme_okpi} provides a \link{ggplot2} theme formatted according to the +Oklahoma Policy Institute style guide for web, with sensible defaults. +} From 62d87fe11f2de463f59f7b2b472882132603741c Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:21:47 -0500 Subject: [PATCH 06/25] started scaffolding theme_tok() and fixed showtext --- DESCRIPTION | 12 ++-- NAMESPACE | 9 ++- R/colors.R | 45 +++++++++++--- R/ojo_set_theme.R | 4 +- R/scales.R | 30 ++++++++++ R/theme_ojo.R | 50 +++++++++++++--- R/theme_okpi.R | 25 ++++---- R/theme_tok.R | 129 +++++++++++++++++++++++++++++++++++++++++ R/zzz.R | 5 ++ man/ojo_set_theme.Rd | 7 +-- man/okpi_palettes.Rd | 1 + man/scale_color_tok.Rd | 20 +++++++ man/scale_fill_tok.Rd | 20 +++++++ man/theme_ojo.Rd | 15 +++-- man/theme_ojo_base.Rd | 22 +++++++ man/theme_okpi_base.Rd | 4 +- man/theme_tok.Rd | 27 +++++++++ man/theme_tok_base.Rd | 26 +++++++++ man/tok_blue.Rd | 16 +++++ man/tok_palettes.Rd | 17 ++++++ 20 files changed, 436 insertions(+), 48 deletions(-) create mode 100644 man/scale_color_tok.Rd create mode 100644 man/scale_fill_tok.Rd create mode 100644 man/theme_ojo_base.Rd create mode 100644 man/theme_tok.Rd create mode 100644 man/theme_tok_base.Rd create mode 100644 man/tok_blue.Rd create mode 100644 man/tok_palettes.Rd diff --git a/DESCRIPTION b/DESCRIPTION index a6f2768..854f531 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,10 +15,12 @@ LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 Depends: - ggplot2 + ggplot2, + showtext Imports: - extrafont, - ggrepel -Suggests: - testthat (>= 3.0.0) + curl, + jsonlite +Suggests: + ggrepel, + testthat (>= 3.0.0) Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 8bc0f01..0ef77de 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -33,12 +33,17 @@ export(palette_ojo_red) export(palette_ojo_spacegray) export(palette_ojo_yellow) export(palette_okpi_main) +export(palette_tok_main) export(scale_color_ojo) export(scale_color_okpi) +export(scale_color_tok) export(scale_fill_ojo) export(scale_fill_okpi) +export(scale_fill_tok) export(theme_ojo) +export(theme_ojo_base) export(theme_okpi) export(theme_okpi_base) -import(extrafont) -import(ggrepel) +export(theme_tok) +export(theme_tok_base) +export(tok_blue) diff --git a/R/colors.R b/R/colors.R index 524c06b..8fb0b02 100644 --- a/R/colors.R +++ b/R/colors.R @@ -1,3 +1,4 @@ +#' OKPI Pallettes ============================================================== #' OKPI Extended Palette #' #' A vector with hex-color codes that correspond to the extended color palette outlined in the Open Justice Oklahoma Data Visualization Style Guide. @@ -73,7 +74,7 @@ okpi_yellow_light <- colorspace::lighten(okpi_yellow, amount = 0.99) #' @export okpi_yellow_palette <- colorRampPalette(c(okpi_yellow_light, okpi_yellow)) -# OJO Palettes +# OJO Palettes ================================================================= #' OJO Main Palette #' #' A vector with hex-color codes for the main OJO palette. @@ -84,14 +85,14 @@ okpi_yellow_palette <- colorRampPalette(c(okpi_yellow_light, okpi_yellow)) #' @rdname ojo_palettes #' @export palette_ojo_main <- c( - cyan = "#1696d2", - yellow = "#fdbf11", - black = "#000000", - gray = "#d2d2d2", - magenta = "#ec008b", - green = "#55b748", - `space gray` = "#5c5859", - red = "#db2b27" + "#1696d2", + "#fdbf11", + "#000000", + "#d2d2d2", + "#ec008b", + "#55b748", + "#5c5859", + "#db2b27" ) #' OJO Diverging Palette @@ -284,3 +285,29 @@ palette_ojo_red <- c( "#6e1614", "#370b0a" ) + +# TOK Palettes ================================================================= + +#' @title TOK main palette +#' @name palette_tok_main +#' @family tok palettes +#' @rdname tok_palettes +#' @export +palette_tok_main <- c( + "#407fc1", # Blue + "#ec2a28", # Red + "#febf66", # Bright Yellow + "#2c9381", # Green + "#dd8000", # Orange + "#533191", # Purple + "#4198af", # Turquoise + "#e26275", # Pink + "#b9cd95", # Light Green + "#a99bbc" # Light Purple +) + +#' @title TOK Blue +#' @export +tok_blue <- "#407fc1" + + diff --git a/R/ojo_set_theme.R b/R/ojo_set_theme.R index ca011ee..36e265e 100644 --- a/R/ojo_set_theme.R +++ b/R/ojo_set_theme.R @@ -16,7 +16,7 @@ #' @md #' @export ojo_set_theme <- function(theme = "okpi", - base_size = 14, + base_size = 18, base_line_size = 0.5, base_rect_size = 0.5, scale = "continuous") { @@ -49,7 +49,7 @@ ojo_set_theme <- function(theme = "okpi", base_rect_size = base_rect_size)) base_family <- "Roboto Condensed" - default_color <- "#407fc1" + default_color <- ojothemes::tok_blue default_palette <- ojothemes::palette_okpi_main } diff --git a/R/scales.R b/R/scales.R index d51cfee..4a4c1e2 100644 --- a/R/scales.R +++ b/R/scales.R @@ -57,3 +57,33 @@ scale_color_ojo <- function() { scale_fill_ojo <- function() { scale_fill_manual(values = palette_ojo_main) } + +#' TOK Color Scale +#' +#' This function returns a ggplot2 color scale using the TOK main palette. +#' +#' @return A ggplot2 scale object. +#' @examples +#' library(ggplot2) +#' ggplot(mtcars, aes(x = wt, y = mpg, color = factor(gear))) + +#' geom_point(size = 3) + +#' scale_color_tok() +#' @export +scale_color_tok <- function() { + scale_color_manual(values = palette_tok_main) +} + +#' TOK Fill Scale +#' +#' This function returns a ggplot2 fill scale using the TOK main palette. +#' +#' @return A ggplot2 scale object. +#' @examples +#' library(ggplot2) +#' ggplot(mtcars, aes(x = factor(gear), fill = factor(gear))) + +#' geom_bar() + +#' scale_fill_tok() +#' @export +scale_fill_tok <- function() { + scale_fill_manual(values = palette_tok_main) +} diff --git a/R/theme_ojo.R b/R/theme_ojo.R index dde354c..2f36a9f 100644 --- a/R/theme_ojo.R +++ b/R/theme_ojo.R @@ -3,16 +3,14 @@ #' \code{theme_ojo} provides a [ggplot2] theme formatted according to the #' Open Justice Oklahoma style guide for web, with sensible defaults. #' -#' @import extrafont -#' @import ggrepel #' @md #' @param base_family,base_size base font family and size #' @param base_line_size,base_rect_size base line and rectangle sizes #' @export -theme_ojo <- function(base_size = 14, - base_family = "Roboto Mono", - base_line_size = 0.5, - base_rect_size = 0.5) { +theme_ojo_base <- function(base_size = 16, + base_family = "Roboto Mono", + base_line_size = 0.5, + base_rect_size = 0.5) { half_line <- base_size / 2L @@ -42,17 +40,17 @@ theme_ojo <- function(base_size = 14, face = "bold", margin = ggplot2::margin(b = 10L)), plot.tag.position = "topleft", - plot.title = ggplot2::element_text(size = base_size * 12 / 8.5, + plot.title = ggplot2::element_text(size = base_size * 14 / 8.5, hjust = 0L, vjust = 0L, face = "bold", margin = ggplot2::margin(b = 10L)), plot.title.position = "plot", - plot.subtitle = ggplot2::element_text(size = base_size * 9.5 / 8.5, + plot.subtitle = ggplot2::element_text(size = base_size * 10 / 8.5, hjust = 0L, vjust = 0L, margin = ggplot2::margin(b = 10L)), - plot.caption = ggplot2::element_text(size = base_size * 7 / 8.5, + plot.caption = ggplot2::element_text(size = base_size * 9 / 8.5, hjust = 1L, vjust = 1L, margin = ggplot2::margin(t = half_line * 0.9)), @@ -161,5 +159,39 @@ theme_ojo <- function(base_size = 14, complete = TRUE ) +} + +#' A [ggplot2] theme formatted in the Oklahoma Policy Institute style +#' +#' \code{theme_okpi} provides a [ggplot2] theme formatted according to the +#' Oklahoma Policy Institute style guide for web, with sensible defaults, +#' and also inclusdes the OKPI fill and color scales. +#' +#' @md +#' @param base_family The font family to use; Roboto Condensed is the default. +#' @param base_size The base font size to use; 14 is the default. +#' @param base_line_size The base line size to use; 0.5 is the default. +#' @param base_rect_size The base rect size to use; 0.5 is the default. +#' @export +theme_ojo <- function(base_size = 14, + base_family = "Roboto Mono", + base_line_size = 0.5, + base_rect_size = 0.5) { + + theme_ojo_base <- theme_ojo_base(base_size = base_size, + base_family = base_family, + base_line_size = base_line_size, + base_rect_size = base_rect_size) + + # Set scales to use okpi palettes + scale_color_ojo <- ojothemes::scale_color_ojo() + scale_fill_ojo <- ojothemes::scale_fill_ojo() + + # Wrap everything together so that the scales are also applied w/ the theme + list( + theme_ojo_base, + scale_color_ojo, + scale_fill_ojo + ) } diff --git a/R/theme_okpi.R b/R/theme_okpi.R index 0c139ae..478e211 100644 --- a/R/theme_okpi.R +++ b/R/theme_okpi.R @@ -5,11 +5,11 @@ #' #' @md #' @param base_family The font family to use; Roboto Condensed is the default. -#' @param base_size The base font size to use; 14 is the default. +#' @param base_size The base font size to use; 16 is the default. #' @param base_line_size The base line size to use; 0.5 is the default. #' @param base_rect_size The base rect size to use; 0.5 is the default. #' @export -theme_okpi_base <- function(base_size = 14, +theme_okpi_base <- function(base_size = 16, base_family = "Roboto Condensed", base_line_size = 0.5, base_rect_size = 0.5) { @@ -43,37 +43,40 @@ theme_okpi_base <- function(base_size = 14, panel.grid.minor.y = ggplot2::element_line(linewidth = 0.25), panel.spacing = grid::unit(6, "pt"), plot.title = ggplot2::element_text( - size = ggplot2::rel(1.66), + size = ggplot2::rel(2), face = "bold", + hjust = 0, color = palette_okpi_main[3], lineheight = 0.7, - hjust = 0, margin = ggplot2::margin(0, 0, 6, 0, "pt") ), plot.title.position = "plot", plot.subtitle = ggplot2::element_text( - size = ggplot2::rel(1.33), + size = ggplot2::rel(1.66), face = "bold.italic", + hjust = 0, family = "Roboto Condensed", lineheight = 0.7, - hjust = 0, margin = ggplot2::margin(0, 0, 6, 0, "pt") ), plot.caption.position = "plot", plot.caption = ggplot2::element_text( - size = ggplot2::rel(1), + size = ggplot2::rel(1.2), lineheight = 0.75, face = "italic", + hjust = 1 ), legend.title = ggplot2::element_blank(), legend.text = ggplot2::element_text(size = ggplot2::rel(1.16)), legend.margin = ggplot2::margin(0, 0, 0, 0), axis.title = ggplot2::element_text( size = ggplot2::rel(1.16), - face = "bold" + face = "bold", + hjust = 0.5, ), axis.text = ggplot2::element_text( - size = ggplot2::rel(1.16) + size = ggplot2::rel(1.16), + hjust = 0.5 ), axis.line.x.bottom = ggplot2::element_line( color = "#333333", @@ -83,7 +86,9 @@ theme_okpi_base <- function(base_size = 14, ), axis.ticks.y = ggplot2::element_blank(), strip.background = ggplot2::element_blank(), - strip.text = ggplot2::element_text(face = "bold") + strip.text = ggplot2::element_text(face = "bold"), + + complete = TRUE ) } diff --git a/R/theme_tok.R b/R/theme_tok.R index e69de29..0ba2f7f 100644 --- a/R/theme_tok.R +++ b/R/theme_tok.R @@ -0,0 +1,129 @@ +#' A [ggplot2] theme formatted in the TOK style +#' +#' \code{theme_tok} provides a [ggplot2] theme formatted according to the +#' Together Oklahoma style guide for web, with sensible defaults. +#' +#' @md +#' @param base_family The font family to use; Roboto Condensed is the default. +#' @param base_size The base font size to use; 16 is the default. +#' @param base_line_size The base line size to use; 0.5 is the default. +#' @param base_rect_size The base rect size to use; 0.5 is the default. +#' @export +theme_tok_base <- function(base_size = 16, + base_family = "Roboto Condensed", + base_line_size = 0.5, + base_rect_size = 0.5) { + + ggplot2::theme( + line = ggplot2::element_line(colour = "#333333", + size = base_line_size, + linetype = 1L, + lineend = "butt"), + rect = ggplot2::element_rect(fill = "#ffffff", + colour = NA, + size = base_rect_size, + linetype = 1L), + text = ggplot2::element_text(family = base_family, + face = "plain", + colour = "#333333", + size = base_size, + angle = 0, + lineheight = 0.9, + margin = ggplot2::margin(), + debug = FALSE), + panel.background = ggplot2::element_rect(fill = colorspace::lighten(tok_blue, amount = 0.75)), + plot.background = ggplot2::element_blank(), + legend.background = ggplot2::element_rect(fill = "transparent", colour = NA), + legend.key = ggplot2::element_rect(fill = "transparent", colour = NA), + legend.position = "bottom", + panel.border = ggplot2::element_blank(), + panel.grid.major.x = ggplot2::element_blank(), + panel.grid.minor.x = ggplot2::element_blank(), + panel.grid.major.y = ggplot2::element_line(linewidth = 0.5), + panel.grid.minor.y = ggplot2::element_blank(), + panel.spacing = grid::unit(6, "pt"), + plot.title = ggplot2::element_text( + size = ggplot2::rel(2), + face = "bold", + hjust = 0, + color = tok_blue, + lineheight = 0.7, + margin = ggplot2::margin(0, 0, 6, 0, "pt") + ), + plot.title.position = "plot", + plot.subtitle = ggplot2::element_text( + size = ggplot2::rel(1.66), + face = "bold.italic", + hjust = 0, + color = ojothemes::palette_tok_main[3], + family = "Roboto Condensed", + lineheight = 0.7, + margin = ggplot2::margin(0, 0, 6, 0, "pt") + ), + plot.caption.position = "plot", + plot.caption = ggplot2::element_text( + size = ggplot2::rel(1.2), + lineheight = 0.75, + face = "italic", + hjust = 1 + ), + legend.title = ggplot2::element_blank(), + legend.text = ggplot2::element_text(size = ggplot2::rel(1.16)), + legend.margin = ggplot2::margin(0, 0, 5, 0), + axis.title = ggplot2::element_text( + size = ggplot2::rel(1.16), + face = "bold", + hjust = 0.5, + ), + axis.text = ggplot2::element_text( + size = ggplot2::rel(1.16), + hjust = 0.5 + ), + axis.line.x.bottom = ggplot2::element_line( + color = "#333333", + ), + axis.ticks = ggplot2::element_line( + color = "#333333", + ), + axis.ticks.y = ggplot2::element_blank(), + strip.background = ggplot2::element_blank(), + strip.text = ggplot2::element_text(face = "bold"), + + complete = TRUE + ) +} + +#' A [ggplot2] theme formatted in the Oklahoma Policy Institute style +#' +#' \code{theme_tok} provides a [ggplot2] theme formatted according to the +#' Oklahoma Policy Institute style guide for web, with sensible defaults, +#' and also inclusdes the tok fill and color scales. +#' +#' @md +#' @param base_family The font family to use; Roboto Condensed is the default. +#' @param base_size The base font size to use; 14 is the default. +#' @param base_line_size The base line size to use; 0.5 is the default. +#' @param base_rect_size The base rect size to use; 0.5 is the default. +#' @export +theme_tok <- function(base_size = 14, + base_family = "Roboto Condensed", + base_line_size = 0.5, + base_rect_size = 0.5) { + + theme_tok_base <- theme_tok_base(base_size = base_size, + base_family = base_family, + base_line_size = base_line_size, + base_rect_size = base_rect_size) + + # Set scales to use tok palettes + scale_color_tok <- ojothemes::scale_color_tok() + scale_fill_tok <- ojothemes::scale_fill_tok() + + # Wrap everything together so that the scales are also applied w/ the theme + list( + theme_tok_base, + scale_color_tok, + scale_fill_tok + ) + +} diff --git a/R/zzz.R b/R/zzz.R index 1fca180..b710a63 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -14,6 +14,11 @@ dpi = 72) } + # Set up showtext + sysfonts::font_add_google("Roboto Mono") + sysfonts::font_add_google("Roboto Condensed") + showtext::showtext_auto() + # check ggplot2 version if (unlist(utils::packageVersion("ggplot2"))[1] < 3) { packageStartupMessage( diff --git a/man/ojo_set_theme.Rd b/man/ojo_set_theme.Rd index 94c695a..4b50fc7 100644 --- a/man/ojo_set_theme.Rd +++ b/man/ojo_set_theme.Rd @@ -6,8 +6,7 @@ \usage{ ojo_set_theme( theme = "okpi", - base_size = 14, - base_family = "Roboto Condensed", + base_size = 18, base_line_size = 0.5, base_rect_size = 0.5, scale = "continuous" @@ -19,8 +18,6 @@ ojo_set_theme( \item{base_size}{The base font size for the theme. All fonts are relative to this value.} -\item{base_family}{The base font family for the theme.} - \item{base_line_size}{The base line size for the theme. All line sizes are relative to this value.} @@ -28,6 +25,8 @@ relative to this value.} relative to this value.} \item{scale}{For \code{theme_ojo_map()}. Should the legend theme be continuous or discrete?} + +\item{base_family}{The base font family for the theme.} } \description{ \code{ojo_set_theme} provides a \link{ggplot2} theme formatted according to the diff --git a/man/okpi_palettes.Rd b/man/okpi_palettes.Rd index 7d2d1ca..557c618 100644 --- a/man/okpi_palettes.Rd +++ b/man/okpi_palettes.Rd @@ -29,6 +29,7 @@ okpi_red okpi_yellow } \description{ +OKPI Pallettes ============================================================== OKPI Extended Palette OKPI Blue Palette diff --git a/man/scale_color_tok.Rd b/man/scale_color_tok.Rd new file mode 100644 index 0000000..204e719 --- /dev/null +++ b/man/scale_color_tok.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scales.R +\name{scale_color_tok} +\alias{scale_color_tok} +\title{TOK Color Scale} +\usage{ +scale_color_tok() +} +\value{ +A ggplot2 scale object. +} +\description{ +This function returns a ggplot2 color scale using the TOK main palette. +} +\examples{ +library(ggplot2) +ggplot(mtcars, aes(x = wt, y = mpg, color = factor(gear))) + + geom_point(size = 3) + + scale_color_tok() +} diff --git a/man/scale_fill_tok.Rd b/man/scale_fill_tok.Rd new file mode 100644 index 0000000..0f435df --- /dev/null +++ b/man/scale_fill_tok.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scales.R +\name{scale_fill_tok} +\alias{scale_fill_tok} +\title{TOK Fill Scale} +\usage{ +scale_fill_tok() +} +\value{ +A ggplot2 scale object. +} +\description{ +This function returns a ggplot2 fill scale using the TOK main palette. +} +\examples{ +library(ggplot2) +ggplot(mtcars, aes(x = factor(gear), fill = factor(gear))) + + geom_bar() + + scale_fill_tok() +} diff --git a/man/theme_ojo.Rd b/man/theme_ojo.Rd index 3106bbf..ae4825a 100644 --- a/man/theme_ojo.Rd +++ b/man/theme_ojo.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/theme_ojo.R \name{theme_ojo} \alias{theme_ojo} -\title{A \link{ggplot2} theme formatted in the Open Justice Oklahoma style} +\title{A \link{ggplot2} theme formatted in the Oklahoma Policy Institute style} \usage{ theme_ojo( base_size = 14, @@ -12,11 +12,16 @@ theme_ojo( ) } \arguments{ -\item{base_family, base_size}{base font family and size} +\item{base_size}{The base font size to use; 14 is the default.} -\item{base_line_size, base_rect_size}{base line and rectangle sizes} +\item{base_family}{The font family to use; Roboto Condensed is the default.} + +\item{base_line_size}{The base line size to use; 0.5 is the default.} + +\item{base_rect_size}{The base rect size to use; 0.5 is the default.} } \description{ -\code{theme_ojo} provides a \link{ggplot2} theme formatted according to the -Open Justice Oklahoma style guide for web, with sensible defaults. +\code{theme_okpi} provides a \link{ggplot2} theme formatted according to the +Oklahoma Policy Institute style guide for web, with sensible defaults, +and also inclusdes the OKPI fill and color scales. } diff --git a/man/theme_ojo_base.Rd b/man/theme_ojo_base.Rd new file mode 100644 index 0000000..4b0effc --- /dev/null +++ b/man/theme_ojo_base.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/theme_ojo.R +\name{theme_ojo_base} +\alias{theme_ojo_base} +\title{A \link{ggplot2} theme formatted in the Open Justice Oklahoma style} +\usage{ +theme_ojo_base( + base_size = 16, + base_family = "Roboto Mono", + base_line_size = 0.5, + base_rect_size = 0.5 +) +} +\arguments{ +\item{base_family, base_size}{base font family and size} + +\item{base_line_size, base_rect_size}{base line and rectangle sizes} +} +\description{ +\code{theme_ojo} provides a \link{ggplot2} theme formatted according to the +Open Justice Oklahoma style guide for web, with sensible defaults. +} diff --git a/man/theme_okpi_base.Rd b/man/theme_okpi_base.Rd index af514cd..8dbca6e 100644 --- a/man/theme_okpi_base.Rd +++ b/man/theme_okpi_base.Rd @@ -5,14 +5,14 @@ \title{A \link{ggplot2} theme formatted in the Oklahoma Policy Institute style} \usage{ theme_okpi_base( - base_size = 14, + base_size = 16, base_family = "Roboto Condensed", base_line_size = 0.5, base_rect_size = 0.5 ) } \arguments{ -\item{base_size}{The base font size to use; 14 is the default.} +\item{base_size}{The base font size to use; 16 is the default.} \item{base_family}{The font family to use; Roboto Condensed is the default.} diff --git a/man/theme_tok.Rd b/man/theme_tok.Rd new file mode 100644 index 0000000..fe78b85 --- /dev/null +++ b/man/theme_tok.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/theme_tok.R +\name{theme_tok} +\alias{theme_tok} +\title{A \link{ggplot2} theme formatted in the Oklahoma Policy Institute style} +\usage{ +theme_tok( + base_size = 14, + base_family = "Roboto Condensed", + base_line_size = 0.5, + base_rect_size = 0.5 +) +} +\arguments{ +\item{base_size}{The base font size to use; 14 is the default.} + +\item{base_family}{The font family to use; Roboto Condensed is the default.} + +\item{base_line_size}{The base line size to use; 0.5 is the default.} + +\item{base_rect_size}{The base rect size to use; 0.5 is the default.} +} +\description{ +\code{theme_tok} provides a \link{ggplot2} theme formatted according to the +Oklahoma Policy Institute style guide for web, with sensible defaults, +and also inclusdes the tok fill and color scales. +} diff --git a/man/theme_tok_base.Rd b/man/theme_tok_base.Rd new file mode 100644 index 0000000..4dfc63c --- /dev/null +++ b/man/theme_tok_base.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/theme_tok.R +\name{theme_tok_base} +\alias{theme_tok_base} +\title{A \link{ggplot2} theme formatted in the TOK style} +\usage{ +theme_tok_base( + base_size = 16, + base_family = "Roboto Condensed", + base_line_size = 0.5, + base_rect_size = 0.5 +) +} +\arguments{ +\item{base_size}{The base font size to use; 16 is the default.} + +\item{base_family}{The font family to use; Roboto Condensed is the default.} + +\item{base_line_size}{The base line size to use; 0.5 is the default.} + +\item{base_rect_size}{The base rect size to use; 0.5 is the default.} +} +\description{ +\code{theme_tok} provides a \link{ggplot2} theme formatted according to the +Together Oklahoma style guide for web, with sensible defaults. +} diff --git a/man/tok_blue.Rd b/man/tok_blue.Rd new file mode 100644 index 0000000..7d41abd --- /dev/null +++ b/man/tok_blue.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{tok_blue} +\alias{tok_blue} +\title{TOK Blue} +\format{ +An object of class \code{character} of length 1. +} +\usage{ +tok_blue +} +\description{ +TOK Blue +} +\keyword{datasets} diff --git a/man/tok_palettes.Rd b/man/tok_palettes.Rd new file mode 100644 index 0000000..05f0351 --- /dev/null +++ b/man/tok_palettes.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_tok_main} +\alias{palette_tok_main} +\title{TOK main palette} +\format{ +An object of class \code{character} of length 10. +} +\usage{ +palette_tok_main +} +\description{ +TOK main palette +} +\concept{tok palettes} +\keyword{datasets} From 8de0eed8651a8697e5276ffa67053e3c66917bec Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:21:53 -0500 Subject: [PATCH 07/25] remove ggrepel dependency --- R/ojo_set_theme.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/R/ojo_set_theme.R b/R/ojo_set_theme.R index 36e265e..e8841f0 100644 --- a/R/ojo_set_theme.R +++ b/R/ojo_set_theme.R @@ -34,19 +34,19 @@ ojo_set_theme <- function(theme = "okpi", default_palette <- ojothemes::palette_okpi_main } else if (theme == "ojo") { - ggplot2::theme_set(theme_ojo(base_size = base_size, - base_line_size = base_line_size, - base_rect_size = base_rect_size)) + ggplot2::theme_set(theme_ojo_base(base_size = base_size, + base_line_size = base_line_size, + base_rect_size = base_rect_size)) base_family <- "Roboto Mono" default_color <- "black" default_palette <- ojothemes::palette_ojo_main } else if (theme == "tok") { - ggplot2::theme_set(theme_tok(base_size = base_size, - base_family = "Roboto Condensed", - base_line_size = base_line_size, - base_rect_size = base_rect_size)) + ggplot2::theme_set(theme_tok_base(base_size = base_size, + base_family = "Roboto Condensed", + base_line_size = base_line_size, + base_rect_size = base_rect_size)) base_family <- "Roboto Condensed" default_color <- ojothemes::tok_blue @@ -57,8 +57,8 @@ ojo_set_theme <- function(theme = "okpi", # add base_family font to text and label geoms --------------------------- ggplot2::update_geom_defaults("text", list(family = base_family)) ggplot2::update_geom_defaults("label", list(family = base_family)) - ggplot2::update_geom_defaults("text_repel", list(family = base_family)) - ggplot2::update_geom_defaults("label_repel", list(family = base_family)) + # ggplot2::update_geom_defaults("text_repel", list(family = base_family)) # Keep ggrepel in this? + # ggplot2::update_geom_defaults("label_repel", list(family = base_family)) # set default color scales ---------------------------------------------- options( From 07a14f2352f9eb07c088252505fbc9e4b0ade136 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:10:43 -0500 Subject: [PATCH 08/25] address all devtools::check() issues --- DESCRIPTION | 38 +- LICENSE.md | 616 ++++++++++++++++++- R/colors.R | 92 +-- R/geoms.R | 44 +- R/ojo_gt.R | 2 +- R/ojo_labs.R | 4 +- R/ojo_set_theme.R | 1 - R/scales.R | 12 +- man/geom_col.Rd | 18 + man/ojo_labs.Rd | 2 + man/ojo_make_caption.Rd | 4 +- man/ojo_palettes.Rd | 110 ---- man/ojo_set_theme.Rd | 2 - man/okpi_blue.Rd | 16 + man/okpi_blue_light.Rd | 16 + man/okpi_blue_palette.Rd | 14 + man/okpi_palettes.Rd | 52 -- man/okpi_red.Rd | 16 + man/okpi_red_light.Rd | 16 + man/okpi_red_palette.Rd | 14 + man/okpi_yellow.Rd | 16 + man/okpi_yellow_light.Rd | 16 + man/okpi_yellow_palette.Rd | 14 + man/palette_ojo_cyan.Rd | 19 + man/palette_ojo_diverging.Rd | 19 + man/palette_ojo_gray.Rd | 19 + man/palette_ojo_green.Rd | 19 + man/palette_ojo_magenta.Rd | 19 + man/palette_ojo_main.Rd | 16 + man/palette_ojo_politics.Rd | 19 + man/palette_ojo_quintile.Rd | 19 + man/palette_ojo_red.Rd | 19 + man/palette_ojo_spacegray.Rd | 19 + man/palette_ojo_yellow.Rd | 19 + man/palette_okpi_main.Rd | 20 + man/{tok_palettes.Rd => palette_tok_main.Rd} | 1 - 36 files changed, 1075 insertions(+), 287 deletions(-) delete mode 100644 man/ojo_palettes.Rd create mode 100644 man/okpi_blue.Rd create mode 100644 man/okpi_blue_light.Rd create mode 100644 man/okpi_blue_palette.Rd delete mode 100644 man/okpi_palettes.Rd create mode 100644 man/okpi_red.Rd create mode 100644 man/okpi_red_light.Rd create mode 100644 man/okpi_red_palette.Rd create mode 100644 man/okpi_yellow.Rd create mode 100644 man/okpi_yellow_light.Rd create mode 100644 man/okpi_yellow_palette.Rd create mode 100644 man/palette_ojo_cyan.Rd create mode 100644 man/palette_ojo_diverging.Rd create mode 100644 man/palette_ojo_gray.Rd create mode 100644 man/palette_ojo_green.Rd create mode 100644 man/palette_ojo_magenta.Rd create mode 100644 man/palette_ojo_main.Rd create mode 100644 man/palette_ojo_politics.Rd create mode 100644 man/palette_ojo_quintile.Rd create mode 100644 man/palette_ojo_red.Rd create mode 100644 man/palette_ojo_spacegray.Rd create mode 100644 man/palette_ojo_yellow.Rd create mode 100644 man/palette_okpi_main.Rd rename man/{tok_palettes.Rd => palette_tok_main.Rd} (93%) diff --git a/DESCRIPTION b/DESCRIPTION index 854f531..729833c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,25 +1,37 @@ Package: ojothemes -Title: What the Package Does (One Line, Title Case) +Title: OJO, OKPI, and TOK themes for {ggplot2} and {gt} Version: 0.0.0.9000 Authors@R: - person(given = "First", - family = "Last", - role = c("aut", "cre"), - email = "first.last@example.com", - comment = c(ORCID = "YOUR-ORCID-ID")) -Description: What the package does (one paragraph). -License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a - license + c( + person( + given = "Andrew", + family = "Bell", + email = "abell@okpolicy.com", + role = c("cre", "aut") + ), + person( + given = "Anthony", + family = "Flores", + email = "aflores@okpolicy.com", + role = "aut" + )) +Description: This package contains themes for {ggplot2} and {gt} that follow the styles of OJO / OKPI / TOK. +License: GPL (>= 3) + file LICENSE Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 Depends: - ggplot2, - showtext Imports: - curl, - jsonlite + colorspace, + dplyr, + ggplot2, + gt, + gtExtras, + rlang, + showtext, + stringr, + sysfonts, Suggests: ggrepel, testthat (>= 3.0.0) diff --git a/LICENSE.md b/LICENSE.md index f007b3f..175443c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,21 +1,595 @@ -# MIT License - -Copyright (c) 2021 ojothemes authors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +GNU General Public License +========================== + +_Version 3, 29 June 2007_ +_Copyright © 2007 Free Software Foundation, Inc. <>_ + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +## Preamble + +The GNU General Public License is a free, copyleft license for software and other +kinds of works. + +The licenses for most software and other practical works are designed to take away +your freedom to share and change the works. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change all versions of a +program--to make sure it remains free software for all its users. We, the Free +Software Foundation, use the GNU General Public License for most of our software; it +applies also to any other work released this way by its authors. You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General +Public Licenses are designed to make sure that you have the freedom to distribute +copies of free software (and charge for them if you wish), that you receive source +code or can get it if you want it, that you can change the software or use pieces of +it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or +asking you to surrender the rights. Therefore, you have certain responsibilities if +you distribute copies of the software, or if you modify it: responsibilities to +respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, +you must pass on to the recipients the same freedoms that you received. You must make +sure that they, too, receive or can get the source code. And you must show them these +terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: **(1)** assert +copyright on the software, and **(2)** offer you this License giving you legal permission +to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is +no warranty for this free software. For both users' and authors' sake, the GPL +requires that modified versions be marked as changed, so that their problems will not +be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of +the software inside them, although the manufacturer can do so. This is fundamentally +incompatible with the aim of protecting users' freedom to change the software. The +systematic pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we have designed +this version of the GPL to prohibit the practice for those products. If such problems +arise substantially in other domains, we stand ready to extend this provision to +those domains in future versions of the GPL, as needed to protect the freedom of +users. + +Finally, every program is threatened constantly by software patents. States should +not allow patents to restrict development and use of software on general-purpose +computers, but in those that do, we wish to avoid the special danger that patents +applied to a free program could make it effectively proprietary. To prevent this, the +GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +## TERMS AND CONDITIONS + +### 0. Definitions + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this +License. Each licensee is addressed as “you”. “Licensees” and +“recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in +a fashion requiring copyright permission, other than the making of an exact copy. The +resulting work is called a “modified version” of the earlier work or a +work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on +the Program. + +To “propagate” a work means to do anything with it that, without +permission, would make you directly or secondarily liable for infringement under +applicable copyright law, except executing it on a computer or modifying a private +copy. Propagation includes copying, distribution (with or without modification), +making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through a computer +network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the +extent that it includes a convenient and prominently visible feature that **(1)** +displays an appropriate copyright notice, and **(2)** tells the user that there is no +warranty for the work (except to the extent that warranties are provided), that +licensees may convey the work under this License, and how to view a copy of this +License. If the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +### 1. Source Code + +The “source code” for a work means the preferred form of the work for +making modifications to it. “Object code” means any non-source form of a +work. + +A “Standard Interface” means an interface that either is an official +standard defined by a recognized standards body, or, in the case of interfaces +specified for a particular programming language, one that is widely used among +developers working in that language. + +The “System Libraries” of an executable work include anything, other than +the work as a whole, that **(a)** is included in the normal form of packaging a Major +Component, but which is not part of that Major Component, and **(b)** serves only to +enable use of the work with that Major Component, or to implement a Standard +Interface for which an implementation is available to the public in source code form. +A “Major Component”, in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system (if any) on which +the executable work runs, or a compiler used to produce the work, or an object code +interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the +source code needed to generate, install, and (for an executable work) run the object +code and to modify the work, including scripts to control those activities. However, +it does not include the work's System Libraries, or general-purpose tools or +generally available free programs which are used unmodified in performing those +activities but which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for the work, and +the source code for shared libraries and dynamically linked subprograms that the work +is specifically designed to require, such as by intimate data communication or +control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate +automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +### 2. Basic Permissions + +All rights granted under this License are granted for the term of copyright on the +Program, and are irrevocable provided the stated conditions are met. This License +explicitly affirms your unlimited permission to run the unmodified Program. The +output from running a covered work is covered by this License only if the output, +given its content, constitutes a covered work. This License acknowledges your rights +of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without +conditions so long as your license otherwise remains in force. You may convey covered +works to others for the sole purpose of having them make modifications exclusively +for you, or provide you with facilities for running those works, provided that you +comply with the terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for you must do so +exclusively on your behalf, under your direction and control, on terms that prohibit +them from making any copies of your copyrighted material outside their relationship +with you. + +Conveying under any other circumstances is permitted solely under the conditions +stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +### 3. Protecting Users' Legal Rights From Anti-Circumvention Law + +No covered work shall be deemed part of an effective technological measure under any +applicable law fulfilling obligations under article 11 of the WIPO copyright treaty +adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention +of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of +technological measures to the extent such circumvention is effected by exercising +rights under this License with respect to the covered work, and you disclaim any +intention to limit operation or modification of the work as a means of enforcing, +against the work's users, your or third parties' legal rights to forbid circumvention +of technological measures. + +### 4. Conveying Verbatim Copies + +You may convey verbatim copies of the Program's source code as you receive it, in any +medium, provided that you conspicuously and appropriately publish on each copy an +appropriate copyright notice; keep intact all notices stating that this License and +any non-permissive terms added in accord with section 7 apply to the code; keep +intact all notices of the absence of any warranty; and give all recipients a copy of +this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer +support or warranty protection for a fee. + +### 5. Conveying Modified Source Versions + +You may convey a work based on the Program, or the modifications to produce it from +the Program, in the form of source code under the terms of section 4, provided that +you also meet all of these conditions: + +* **a)** The work must carry prominent notices stating that you modified it, and giving a +relevant date. +* **b)** The work must carry prominent notices stating that it is released under this +License and any conditions added under section 7. This requirement modifies the +requirement in section 4 to “keep intact all notices”. +* **c)** You must license the entire work, as a whole, under this License to anyone who +comes into possession of a copy. This License will therefore apply, along with any +applicable section 7 additional terms, to the whole of the work, and all its parts, +regardless of how they are packaged. This License gives no permission to license the +work in any other way, but it does not invalidate such permission if you have +separately received it. +* **d)** If the work has interactive user interfaces, each must display Appropriate Legal +Notices; however, if the Program has interactive interfaces that do not display +Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are +not by their nature extensions of the covered work, and which are not combined with +it such as to form a larger program, in or on a volume of a storage or distribution +medium, is called an “aggregate” if the compilation and its resulting +copyright are not used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work in an aggregate +does not cause this License to apply to the other parts of the aggregate. + +### 6. Conveying Non-Source Forms + +You may convey a covered work in object code form under the terms of sections 4 and +5, provided that you also convey the machine-readable Corresponding Source under the +terms of this License, in one of these ways: + +* **a)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by the Corresponding Source fixed on a +durable physical medium customarily used for software interchange. +* **b)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by a written offer, valid for at least +three years and valid for as long as you offer spare parts or customer support for +that product model, to give anyone who possesses the object code either **(1)** a copy of +the Corresponding Source for all the software in the product that is covered by this +License, on a durable physical medium customarily used for software interchange, for +a price no more than your reasonable cost of physically performing this conveying of +source, or **(2)** access to copy the Corresponding Source from a network server at no +charge. +* **c)** Convey individual copies of the object code with a copy of the written offer to +provide the Corresponding Source. This alternative is allowed only occasionally and +noncommercially, and only if you received the object code with such an offer, in +accord with subsection 6b. +* **d)** Convey the object code by offering access from a designated place (gratis or for +a charge), and offer equivalent access to the Corresponding Source in the same way +through the same place at no further charge. You need not require recipients to copy +the Corresponding Source along with the object code. If the place to copy the object +code is a network server, the Corresponding Source may be on a different server +(operated by you or a third party) that supports equivalent copying facilities, +provided you maintain clear directions next to the object code saying where to find +the Corresponding Source. Regardless of what server hosts the Corresponding Source, +you remain obligated to ensure that it is available for as long as needed to satisfy +these requirements. +* **e)** Convey the object code using peer-to-peer transmission, provided you inform +other peers where the object code and Corresponding Source of the work are being +offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the +Corresponding Source as a System Library, need not be included in conveying the +object code work. + +A “User Product” is either **(1)** a “consumer product”, which +means any tangible personal property which is normally used for personal, family, or +household purposes, or **(2)** anything designed or sold for incorporation into a +dwelling. In determining whether a product is a consumer product, doubtful cases +shall be resolved in favor of coverage. For a particular product received by a +particular user, “normally used” refers to a typical or common use of +that class of product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected to use, the +product. A product is a consumer product regardless of whether the product has +substantial commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, +procedures, authorization keys, or other information required to install and execute +modified versions of a covered work in that User Product from a modified version of +its Corresponding Source. The information must suffice to ensure that the continued +functioning of the modified object code is in no case prevented or interfered with +solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for +use in, a User Product, and the conveying occurs as part of a transaction in which +the right of possession and use of the User Product is transferred to the recipient +in perpetuity or for a fixed term (regardless of how the transaction is +characterized), the Corresponding Source conveyed under this section must be +accompanied by the Installation Information. But this requirement does not apply if +neither you nor any third party retains the ability to install modified object code +on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to +continue to provide support service, warranty, or updates for a work that has been +modified or installed by the recipient, or for the User Product in which it has been +modified or installed. Access to a network may be denied when the modification itself +materially and adversely affects the operation of the network or violates the rules +and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with +this section must be in a format that is publicly documented (and with an +implementation available to the public in source code form), and must require no +special password or key for unpacking, reading or copying. + +### 7. Additional Terms + +“Additional permissions” are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. Additional +permissions that are applicable to the entire Program shall be treated as though they +were included in this License, to the extent that they are valid under applicable +law. If additional permissions apply only to part of the Program, that part may be +used separately under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any +additional permissions from that copy, or from any part of it. (Additional +permissions may be written to require their own removal in certain cases when you +modify the work.) You may place additional permissions on material, added by you to a +covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a +covered work, you may (if authorized by the copyright holders of that material) +supplement the terms of this License with terms: + +* **a)** Disclaiming warranty or limiting liability differently from the terms of +sections 15 and 16 of this License; or +* **b)** Requiring preservation of specified reasonable legal notices or author +attributions in that material or in the Appropriate Legal Notices displayed by works +containing it; or +* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that +modified versions of such material be marked in reasonable ways as different from the +original version; or +* **d)** Limiting the use for publicity purposes of names of licensors or authors of the +material; or +* **e)** Declining to grant rights under trademark law for use of some trade names, +trademarks, or service marks; or +* **f)** Requiring indemnification of licensors and authors of that material by anyone +who conveys the material (or modified versions of it) with contractual assumptions of +liability to the recipient, for any liability that these contractual assumptions +directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further +restrictions” within the meaning of section 10. If the Program as you received +it, or any part of it, contains a notice stating that it is governed by this License +along with a term that is a further restriction, you may remove that term. If a +license document contains a further restriction but permits relicensing or conveying +under this License, you may add to a covered work material governed by the terms of +that license document, provided that the further restriction does not survive such +relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in +the relevant source files, a statement of the additional terms that apply to those +files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a +separately written license, or stated as exceptions; the above requirements apply +either way. + +### 8. Termination + +You may not propagate or modify a covered work except as expressly provided under +this License. Any attempt otherwise to propagate or modify it is void, and will +automatically terminate your rights under this License (including any patent licenses +granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a +particular copyright holder is reinstated **(a)** provisionally, unless and until the +copyright holder explicitly and finally terminates your license, and **(b)** permanently, +if the copyright holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently +if the copyright holder notifies you of the violation by some reasonable means, this +is the first time you have received notice of violation of this License (for any +work) from that copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of +parties who have received copies or rights from you under this License. If your +rights have been terminated and not permanently reinstated, you do not qualify to +receive new licenses for the same material under section 10. + +### 9. Acceptance Not Required for Having Copies + +You are not required to accept this License in order to receive or run a copy of the +Program. Ancillary propagation of a covered work occurring solely as a consequence of +using peer-to-peer transmission to receive a copy likewise does not require +acceptance. However, nothing other than this License grants you permission to +propagate or modify any covered work. These actions infringe copyright if you do not +accept this License. Therefore, by modifying or propagating a covered work, you +indicate your acceptance of this License to do so. + +### 10. Automatic Licensing of Downstream Recipients + +Each time you convey a covered work, the recipient automatically receives a license +from the original licensors, to run, modify and propagate that work, subject to this +License. You are not responsible for enforcing compliance by third parties with this +License. + +An “entity transaction” is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an organization, or +merging organizations. If propagation of a covered work results from an entity +transaction, each party to that transaction who receives a copy of the work also +receives whatever licenses to the work the party's predecessor in interest had or +could give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if the predecessor +has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or +affirmed under this License. For example, you may not impose a license fee, royalty, +or other charge for exercise of rights granted under this License, and you may not +initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging +that any patent claim is infringed by making, using, selling, offering for sale, or +importing the Program or any portion of it. + +### 11. Patents + +A “contributor” is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The work thus +licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or +controlled by the contributor, whether already acquired or hereafter acquired, that +would be infringed by some manner, permitted by this License, of making, using, or +selling its contributor version, but do not include claims that would be infringed +only as a consequence of further modification of the contributor version. For +purposes of this definition, “control” includes the right to grant patent +sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license +under the contributor's essential patent claims, to make, use, sell, offer for sale, +import and otherwise run, modify and propagate the contents of its contributor +version. + +In the following three paragraphs, a “patent license” is any express +agreement or commitment, however denominated, not to enforce a patent (such as an +express permission to practice a patent or covenant not to sue for patent +infringement). To “grant” such a patent license to a party means to make +such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the +Corresponding Source of the work is not available for anyone to copy, free of charge +and under the terms of this License, through a publicly available network server or +other readily accessible means, then you must either **(1)** cause the Corresponding +Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the +patent license for this particular work, or **(3)** arrange, in a manner consistent with +the requirements of this License, to extend the patent license to downstream +recipients. “Knowingly relying” means you have actual knowledge that, but +for the patent license, your conveying the covered work in a country, or your +recipient's use of the covered work in a country, would infringe one or more +identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you +convey, or propagate by procuring conveyance of, a covered work, and grant a patent +license to some of the parties receiving the covered work authorizing them to use, +propagate, modify or convey a specific copy of the covered work, then the patent +license you grant is automatically extended to all recipients of the covered work and +works based on it. + +A patent license is “discriminatory” if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on the +non-exercise of one or more of the rights that are specifically granted under this +License. You may not convey a covered work if you are a party to an arrangement with +a third party that is in the business of distributing software, under which you make +payment to the third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties who would receive +the covered work from you, a discriminatory patent license **(a)** in connection with +copies of the covered work conveyed by you (or copies made from those copies), or **(b)** +primarily for and in connection with specific products or compilations that contain +the covered work, unless you entered into that arrangement, or that patent license +was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied +license or other defenses to infringement that may otherwise be available to you +under applicable patent law. + +### 12. No Surrender of Others' Freedom + +If conditions are imposed on you (whether by court order, agreement or otherwise) +that contradict the conditions of this License, they do not excuse you from the +conditions of this License. If you cannot convey a covered work so as to satisfy +simultaneously your obligations under this License and any other pertinent +obligations, then as a consequence you may not convey it at all. For example, if you +agree to terms that obligate you to collect a royalty for further conveying from +those to whom you convey the Program, the only way you could satisfy both those terms +and this License would be to refrain entirely from conveying the Program. + +### 13. Use with the GNU Affero General Public License + +Notwithstanding any other provision of this License, you have permission to link or +combine any covered work with a work licensed under version 3 of the GNU Affero +General Public License into a single combined work, and to convey the resulting work. +The terms of this License will continue to apply to the part which is the covered +work, but the special requirements of the GNU Affero General Public License, section +13, concerning interaction through a network will apply to the combination as such. + +### 14. Revised Versions of this License + +The Free Software Foundation may publish revised and/or new versions of the GNU +General Public License from time to time. Such new versions will be similar in spirit +to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that +a certain numbered version of the GNU General Public License “or any later +version” applies to it, you have the option of following the terms and +conditions either of that numbered version or of any later version published by the +Free Software Foundation. If the Program does not specify a version number of the GNU +General Public License, you may choose any version ever published by the Free +Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU +General Public License can be used, that proxy's public statement of acceptance of a +version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no +additional obligations are imposed on any author or copyright holder as a result of +your choosing to follow a later version. + +### 15. Disclaimer of Warranty + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE +QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +### 16. Limitation of Liability + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY +COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS +PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, +INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE +OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE +WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +### 17. Interpretation of Sections 15 and 16 + +If the disclaimer of warranty and limitation of liability provided above cannot be +given local legal effect according to their terms, reviewing courts shall apply local +law that most closely approximates an absolute waiver of all civil liability in +connection with the Program, unless a warranty or assumption of liability accompanies +a copy of the Program in return for a fee. + +_END OF TERMS AND CONDITIONS_ + +## How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to +the public, the best way to achieve this is to make it free software which everyone +can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them +to the start of each source file to most effectively state the exclusion of warranty; +and each file should have at least the “copyright” line and a pointer to +where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this +when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type 'show c' for details. + +The hypothetical commands `show w` and `show c` should show the appropriate parts of +the General Public License. Of course, your program's commands might be different; +for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to +sign a “copyright disclaimer” for the program, if necessary. For more +information on this, and how to apply and follow the GNU GPL, see +<>. + +The GNU General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may consider it +more useful to permit linking proprietary applications with the library. If this is +what you want to do, use the GNU Lesser General Public License instead of this +License. But first, please read +<>. diff --git a/R/colors.R b/R/colors.R index 8fb0b02..98bd19f 100644 --- a/R/colors.R +++ b/R/colors.R @@ -1,13 +1,10 @@ -#' OKPI Pallettes ============================================================== -#' OKPI Extended Palette +#' OKPI Palettes #' #' A vector with hex-color codes that correspond to the extended color palette outlined in the Open Justice Oklahoma Data Visualization Style Guide. #' \url{http://openjusticeok.github.io/styleguide/} #' #' @title OKPI main palette #' @name palette_okpi_main -#' @family okpi palettes -#' @rdname okpi_palettes #' @export palette_okpi_main <- c( "#2f507f", # Dark Blue @@ -26,63 +23,56 @@ palette_okpi_main <- c( "#a99bbc" # Light Purple ) -# Blue Palette -#' OKPI Blue Palette -#' -#' A palette of blue shades for OKPI. -#' -#' @title OKPI Blue Palette -#' @name okpi_blue_palette -#' @family okpi palettes -#' @rdname okpi_palettes +#' @title OKPI blue +#' @name okpi_blue #' @export okpi_blue <- "#2a5180" +#' @title OKPI blue light +#' @name okpi_blue_light #' @export okpi_blue_light <- colorspace::lighten(okpi_blue, amount = 0.95) +#' @title OKPI Blue palette +#' @name okpi_blue_palette +#' +#' @param n The number of colors to return +#' #' @export okpi_blue_palette <- colorRampPalette(c(okpi_blue_light, okpi_blue)) -# Red Palette -#' OKPI Red Palette -#' -#' A palette of red shades for OKPI. -#' -#' @title OKPI Red Palette -#' @name okpi_red_palette -#' @family okpi palettes -#' @rdname okpi_palettes +#' @title OKPI Red +#' @name okpi_red #' @export okpi_red <- "#982422" +#' @title OKPI Red light +#' @name okpi_red_light #' @export okpi_red_light <- colorspace::lighten(okpi_red, amount = 0.95) +#' @title OKPI Red palette +#' @name okpi_red_palette +#' +#' @param n The number of colors to return +#' #' @export okpi_red_palette <- colorRampPalette(c(okpi_red_light, okpi_red)) -# Yellow Palette -#' OKPI Yellow Palette -#' -#' A palette of yellow shades for OKPI. -#' -#' @title OKPI Yellow Palette -#' @name okpi_yellow_palette -#' @family okpi palettes -#' @rdname okpi_palettes +#' @title OKPI yellow +#' @name okpi_yellow #' @export okpi_yellow <- "#fdbc5f" +#' @title OKPI yellow light +#' @name okpi_yellow_light #' @export okpi_yellow_light <- colorspace::lighten(okpi_yellow, amount = 0.99) +#' @title OKPI Yellow palette +#' @name okpi_yellow_palette +#' +#' @param n The number of colors to return +#' #' @export okpi_yellow_palette <- colorRampPalette(c(okpi_yellow_light, okpi_yellow)) -# OJO Palettes ================================================================= -#' OJO Main Palette -#' -#' A vector with hex-color codes for the main OJO palette. -#' #' @title OJO Main Palette #' @name palette_ojo_main -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_main <- c( "#1696d2", @@ -101,8 +91,6 @@ palette_ojo_main <- c( #' #' @title OJO Diverging Palette #' @name palette_ojo_diverging -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_diverging <- c( "#ca5800", @@ -121,8 +109,6 @@ palette_ojo_diverging <- c( #' #' @title OJO Quintile Palette #' @name palette_ojo_quintile -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_quintile <- c( "#cfe8f3", @@ -138,8 +124,6 @@ palette_ojo_quintile <- c( #' #' @title OJO Politics Palette #' @name palette_ojo_politics -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_politics <- c( "#1696d2", @@ -152,8 +136,6 @@ palette_ojo_politics <- c( #' #' @title OJO Cyan Palette #' @name palette_ojo_cyan -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_cyan <- c( "#cfe8f3", @@ -172,8 +154,6 @@ palette_ojo_cyan <- c( #' #' @title OJO Gray Palette #' @name palette_ojo_gray -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_gray <- c( "#f5f5f5", @@ -192,8 +172,6 @@ palette_ojo_gray <- c( #' #' @title OJO Yellow Palette #' @name palette_ojo_yellow -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_yellow <- c( "#fff2cf", @@ -212,8 +190,6 @@ palette_ojo_yellow <- c( #' #' @title OJO Magenta Palette #' @name palette_ojo_magenta -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_magenta <- c( "#f5cbdf", @@ -232,8 +208,6 @@ palette_ojo_magenta <- c( #' #' @title OJO Green Palette #' @name palette_ojo_green -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_green <- c( "#dcedd9", @@ -252,8 +226,6 @@ palette_ojo_green <- c( #' #' @title OJO Space Gray Palette #' @name palette_ojo_spacegray -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_spacegray <- c( "#d5d5d4", @@ -272,8 +244,6 @@ palette_ojo_spacegray <- c( #' #' @title OJO Red Palette #' @name palette_ojo_red -#' @family ojo palettes -#' @rdname ojo_palettes #' @export palette_ojo_red <- c( "#f8d5d4", @@ -286,12 +256,8 @@ palette_ojo_red <- c( "#370b0a" ) -# TOK Palettes ================================================================= - #' @title TOK main palette #' @name palette_tok_main -#' @family tok palettes -#' @rdname tok_palettes #' @export palette_tok_main <- c( "#407fc1", # Blue @@ -306,7 +272,9 @@ palette_tok_main <- c( "#a99bbc" # Light Purple ) +#' TOK Blue #' @title TOK Blue +#' @name tok_blue #' @export tok_blue <- "#407fc1" diff --git a/R/geoms.R b/R/geoms.R index 45476c1..4237235 100644 --- a/R/geoms.R +++ b/R/geoms.R @@ -1,24 +1,27 @@ #' @title OJO version of the ggproto GeomCol object +#' #' @description #' This is a near-exact copy of the default ggplot2 GeomCol ggproto object. #' The only difference is that I've adjusted it to make the default column width smaller. #' This ensures that it looks right no matter what the scale of the data you're using. -GeomColOJO <- ggproto("GeomCol", GeomRect, - required_aes = c("x", "y"), +GeomColOJO <- ggplot2::ggproto( + "GeomCol", + ggplot2::GeomRect, + required_aes = c("x", "y"), - setup_data = function(data, params) { - data$width <- data$width %||% - params$width %||% (resolution(data$x, FALSE) * 0.7) # Set to 70% of resolution rather than default 90% - transform(data, - ymin = pmin(y, 0), ymax = pmax(y, 0), - xmin = x - width / 2, xmax = x + width / 2, width = NULL - ) - }, + setup_data = function(data, params) { + data$width <- data$width %||% + params$width %||% (ggplot2::resolution(data$x, FALSE) * 0.7) # Set to 70% of resolution rather than default 90% + transform(data, + ymin = pmin(y, 0), ymax = pmax(y, 0), + xmin = x - width / 2, xmax = x + width / 2, width = NULL + ) + }, - draw_panel = function(self, data, panel_params, coord, width = NULL) { - # Hack to ensure that width is detected as a parameter - ggproto_parent(GeomRect, self)$draw_panel(data, panel_params, coord) - } + draw_panel = function(self, data, panel_params, coord, width = NULL) { + # Hack to ensure that width is detected as a parameter + ggplot2::ggproto_parent(GeomRect, self)$draw_panel(data, panel_params, coord) + } ) #' geom_col in the Open Justice Oklahoma style @@ -27,6 +30,17 @@ GeomColOJO <- ggproto("GeomCol", GeomRect, #' A custom version of the geom_col() geom that uses the OJO version of the ggproto object instead of the default #' (this makes the bars skinnier and nice looking consistently) #' +#' @param mapping Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping. +#' @param data The data to be displayed in this layer. There are three options: +#' If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot(). +#' A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created. +#' A function will be called with a single argument, the plot data. The return value must be a data.frame., and will be used as the layer data. +#' @param position Position adjustment, either as a string, or the result of a call to a position adjustment function. +#' @param ... Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like color = "red" or size = 3. They may also be parameters to the paired geom/stat. +#' @param na.rm If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed. +#' @param show.legend logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. +#' @param inherit.aes If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders. +#' #' @md #' @export geom_col <- function(mapping = NULL, data = NULL, @@ -36,7 +50,7 @@ geom_col <- function(mapping = NULL, data = NULL, show.legend = NA, inherit.aes = TRUE) { - layer( + ggplot2::layer( data = data, mapping = mapping, stat = "identity", diff --git a/R/ojo_gt.R b/R/ojo_gt.R index ccfeb0d..bad2c06 100644 --- a/R/ojo_gt.R +++ b/R/ojo_gt.R @@ -14,7 +14,7 @@ ojo_gt <- function(data, title = NA, subtitle = NA) { gt::gt() |> gtExtras::gt_theme_nytimes() |> gt::tab_spanner( - label = str_to_titlecase(colnames(data)) + label = stringr::str_to_title(colnames(data)) ) |> gt::tab_options( column_labels.font.size = "medium", diff --git a/R/ojo_labs.R b/R/ojo_labs.R index b4faf15..cf1922b 100644 --- a/R/ojo_labs.R +++ b/R/ojo_labs.R @@ -3,7 +3,7 @@ #' Creates the text for a caption to add to ggplots and gt tables, including consistent default "source: " statements. #' #' @param source The domain / source of the data. Can be one of "oscn", "ocdc", or "ppb" for canned text, NA for no source, or a custom string. -#' @param name The name of the analyst to credit +#' @param analyst_name The name of the analyst to credit #' @returns A string with the caption text #' @export ojo_make_caption <- function(analyst_name = NA, @@ -43,6 +43,8 @@ ojo_make_caption <- function(analyst_name = NA, #' #' @param analyst_name The name of the analyst to credit #' @param source The data source / source of the data. +#' @param ... Other arguments passed to labs() +#' #' @export ojo_labs <- function (..., analyst_name = NA, diff --git a/R/ojo_set_theme.R b/R/ojo_set_theme.R index e8841f0..4ec24dd 100644 --- a/R/ojo_set_theme.R +++ b/R/ojo_set_theme.R @@ -6,7 +6,6 @@ #' @param theme The theme you wish to use. Options are "okpi", "ojo", or "tok". #' @param base_size The base font size for the theme. All fonts are relative to #' this value. -#' @param base_family The base font family for the theme. #' @param base_line_size The base line size for the theme. All line sizes are #' relative to this value. #' @param base_rect_size The base rect size for the theme. All rect sizes are diff --git a/R/scales.R b/R/scales.R index 4a4c1e2..f1b6f41 100644 --- a/R/scales.R +++ b/R/scales.R @@ -10,7 +10,7 @@ #' scale_color_okpi() #' @export scale_color_okpi <- function() { - scale_color_manual(values = palette_okpi_main) + ggplot2::scale_color_manual(values = palette_okpi_main) } #' OKPI Fill Scale @@ -25,7 +25,7 @@ scale_color_okpi <- function() { #' scale_fill_okpi() #' @export scale_fill_okpi <- function() { - scale_fill_manual(values = palette_okpi_main) + ggplot2::scale_fill_manual(values = palette_okpi_main) } #' OJO Color Scale @@ -40,7 +40,7 @@ scale_fill_okpi <- function() { #' scale_color_ojo() #' @export scale_color_ojo <- function() { - scale_color_manual(values = palette_ojo_main) + ggplot2::scale_color_manual(values = palette_ojo_main) } #' OJO Fill Scale @@ -55,7 +55,7 @@ scale_color_ojo <- function() { #' scale_fill_ojo() #' @export scale_fill_ojo <- function() { - scale_fill_manual(values = palette_ojo_main) + ggplot2::scale_fill_manual(values = palette_ojo_main) } #' TOK Color Scale @@ -70,7 +70,7 @@ scale_fill_ojo <- function() { #' scale_color_tok() #' @export scale_color_tok <- function() { - scale_color_manual(values = palette_tok_main) + ggplot2::scale_color_manual(values = palette_tok_main) } #' TOK Fill Scale @@ -85,5 +85,5 @@ scale_color_tok <- function() { #' scale_fill_tok() #' @export scale_fill_tok <- function() { - scale_fill_manual(values = palette_tok_main) + ggplot2::scale_fill_manual(values = palette_tok_main) } diff --git a/man/geom_col.Rd b/man/geom_col.Rd index f4a9030..624f55b 100644 --- a/man/geom_col.Rd +++ b/man/geom_col.Rd @@ -14,6 +14,24 @@ geom_col( inherit.aes = TRUE ) } +\arguments{ +\item{mapping}{Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.} + +\item{data}{The data to be displayed in this layer. There are three options: +If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot(). +A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created. +A function will be called with a single argument, the plot data. The return value must be a data.frame., and will be used as the layer data.} + +\item{position}{Position adjustment, either as a string, or the result of a call to a position adjustment function.} + +\item{...}{Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like color = "red" or size = 3. They may also be parameters to the paired geom/stat.} + +\item{na.rm}{If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.} + +\item{show.legend}{logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.} + +\item{inherit.aes}{If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders.} +} \description{ A custom version of the geom_col() geom that uses the OJO version of the ggproto object instead of the default (this makes the bars skinnier and nice looking consistently) diff --git a/man/ojo_labs.Rd b/man/ojo_labs.Rd index 23f37d4..6acdd8b 100644 --- a/man/ojo_labs.Rd +++ b/man/ojo_labs.Rd @@ -7,6 +7,8 @@ ojo_labs(..., analyst_name = NA, source = NA) } \arguments{ +\item{...}{Other arguments passed to labs()} + \item{analyst_name}{The name of the analyst to credit} \item{source}{The data source / source of the data.} diff --git a/man/ojo_make_caption.Rd b/man/ojo_make_caption.Rd index 38ed3f1..53af0db 100644 --- a/man/ojo_make_caption.Rd +++ b/man/ojo_make_caption.Rd @@ -7,9 +7,9 @@ ojo_make_caption(analyst_name = NA, source = NA) } \arguments{ -\item{source}{The domain / source of the data. Can be one of "oscn", "ocdc", or "ppb" for canned text, NA for no source, or a custom string.} +\item{analyst_name}{The name of the analyst to credit} -\item{name}{The name of the analyst to credit} +\item{source}{The domain / source of the data. Can be one of "oscn", "ocdc", or "ppb" for canned text, NA for no source, or a custom string.} } \value{ A string with the caption text diff --git a/man/ojo_palettes.Rd b/man/ojo_palettes.Rd deleted file mode 100644 index b694e20..0000000 --- a/man/ojo_palettes.Rd +++ /dev/null @@ -1,110 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/colors.R -\docType{data} -\name{palette_ojo_main} -\alias{palette_ojo_main} -\alias{palette_ojo_diverging} -\alias{palette_ojo_quintile} -\alias{palette_ojo_politics} -\alias{palette_ojo_cyan} -\alias{palette_ojo_gray} -\alias{palette_ojo_yellow} -\alias{palette_ojo_magenta} -\alias{palette_ojo_green} -\alias{palette_ojo_spacegray} -\alias{palette_ojo_red} -\title{OJO Main Palette} -\format{ -An object of class \code{character} of length 8. - -An object of class \code{character} of length 8. - -An object of class \code{character} of length 5. - -An object of class \code{character} of length 2. - -An object of class \code{character} of length 8. - -An object of class \code{character} of length 8. - -An object of class \code{character} of length 8. - -An object of class \code{character} of length 8. - -An object of class \code{character} of length 8. - -An object of class \code{character} of length 8. - -An object of class \code{character} of length 8. -} -\usage{ -palette_ojo_main - -palette_ojo_diverging - -palette_ojo_quintile - -palette_ojo_politics - -palette_ojo_cyan - -palette_ojo_gray - -palette_ojo_yellow - -palette_ojo_magenta - -palette_ojo_green - -palette_ojo_spacegray - -palette_ojo_red -} -\description{ -OJO Main Palette - -OJO Diverging Palette - -OJO Quintile Palette - -OJO Politics Palette - -OJO Cyan Palette - -OJO Gray Palette - -OJO Yellow Palette - -OJO Magenta Palette - -OJO Green Palette - -OJO Space Gray Palette - -OJO Red Palette -} -\details{ -A vector with hex-color codes for the main OJO palette. - -A vector with hex-color codes for the OJO diverging palette. - -A vector with hex-color codes for the OJO quintile palette. - -A vector with hex-color codes for the OJO politics palette. - -A vector with hex-color codes for the OJO cyan palette. - -A vector with hex-color codes for the OJO gray palette. - -A vector with hex-color codes for the OJO yellow palette. - -A vector with hex-color codes for the OJO magenta palette. - -A vector with hex-color codes for the OJO green palette. - -A vector with hex-color codes for the OJO space gray palette. - -A vector with hex-color codes for the OJO red palette. -} -\concept{ojo palettes} -\keyword{datasets} diff --git a/man/ojo_set_theme.Rd b/man/ojo_set_theme.Rd index 4b50fc7..0fe3a43 100644 --- a/man/ojo_set_theme.Rd +++ b/man/ojo_set_theme.Rd @@ -25,8 +25,6 @@ relative to this value.} relative to this value.} \item{scale}{For \code{theme_ojo_map()}. Should the legend theme be continuous or discrete?} - -\item{base_family}{The base font family for the theme.} } \description{ \code{ojo_set_theme} provides a \link{ggplot2} theme formatted according to the diff --git a/man/okpi_blue.Rd b/man/okpi_blue.Rd new file mode 100644 index 0000000..16b6e42 --- /dev/null +++ b/man/okpi_blue.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{okpi_blue} +\alias{okpi_blue} +\title{OKPI blue} +\format{ +An object of class \code{character} of length 1. +} +\usage{ +okpi_blue +} +\description{ +OKPI blue +} +\keyword{datasets} diff --git a/man/okpi_blue_light.Rd b/man/okpi_blue_light.Rd new file mode 100644 index 0000000..098a168 --- /dev/null +++ b/man/okpi_blue_light.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{okpi_blue_light} +\alias{okpi_blue_light} +\title{OKPI blue light} +\format{ +An object of class \code{character} of length 1. +} +\usage{ +okpi_blue_light +} +\description{ +OKPI blue light +} +\keyword{datasets} diff --git a/man/okpi_blue_palette.Rd b/man/okpi_blue_palette.Rd new file mode 100644 index 0000000..27616e9 --- /dev/null +++ b/man/okpi_blue_palette.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\name{okpi_blue_palette} +\alias{okpi_blue_palette} +\title{OKPI Blue palette} +\usage{ +okpi_blue_palette(n) +} +\arguments{ +\item{n}{The number of colors to return} +} +\description{ +OKPI Blue palette +} diff --git a/man/okpi_palettes.Rd b/man/okpi_palettes.Rd deleted file mode 100644 index 557c618..0000000 --- a/man/okpi_palettes.Rd +++ /dev/null @@ -1,52 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/colors.R -\docType{data} -\name{palette_okpi_main} -\alias{palette_okpi_main} -\alias{okpi_blue_palette} -\alias{okpi_blue} -\alias{okpi_red_palette} -\alias{okpi_red} -\alias{okpi_yellow_palette} -\alias{okpi_yellow} -\title{OKPI main palette} -\format{ -An object of class \code{character} of length 14. - -An object of class \code{character} of length 1. - -An object of class \code{character} of length 1. - -An object of class \code{character} of length 1. -} -\usage{ -palette_okpi_main - -okpi_blue - -okpi_red - -okpi_yellow -} -\description{ -OKPI Pallettes ============================================================== -OKPI Extended Palette - -OKPI Blue Palette - -OKPI Red Palette - -OKPI Yellow Palette -} -\details{ -A vector with hex-color codes that correspond to the extended color palette outlined in the Open Justice Oklahoma Data Visualization Style Guide. -\url{http://openjusticeok.github.io/styleguide/} - -A palette of blue shades for OKPI. - -A palette of red shades for OKPI. - -A palette of yellow shades for OKPI. -} -\concept{okpi palettes} -\keyword{datasets} diff --git a/man/okpi_red.Rd b/man/okpi_red.Rd new file mode 100644 index 0000000..693cabb --- /dev/null +++ b/man/okpi_red.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{okpi_red} +\alias{okpi_red} +\title{OKPI Red} +\format{ +An object of class \code{character} of length 1. +} +\usage{ +okpi_red +} +\description{ +OKPI Red +} +\keyword{datasets} diff --git a/man/okpi_red_light.Rd b/man/okpi_red_light.Rd new file mode 100644 index 0000000..f15504d --- /dev/null +++ b/man/okpi_red_light.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{okpi_red_light} +\alias{okpi_red_light} +\title{OKPI Red light} +\format{ +An object of class \code{character} of length 1. +} +\usage{ +okpi_red_light +} +\description{ +OKPI Red light +} +\keyword{datasets} diff --git a/man/okpi_red_palette.Rd b/man/okpi_red_palette.Rd new file mode 100644 index 0000000..a576290 --- /dev/null +++ b/man/okpi_red_palette.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\name{okpi_red_palette} +\alias{okpi_red_palette} +\title{OKPI Red palette} +\usage{ +okpi_red_palette(n) +} +\arguments{ +\item{n}{The number of colors to return} +} +\description{ +OKPI Red palette +} diff --git a/man/okpi_yellow.Rd b/man/okpi_yellow.Rd new file mode 100644 index 0000000..cd9d07c --- /dev/null +++ b/man/okpi_yellow.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{okpi_yellow} +\alias{okpi_yellow} +\title{OKPI yellow} +\format{ +An object of class \code{character} of length 1. +} +\usage{ +okpi_yellow +} +\description{ +OKPI yellow +} +\keyword{datasets} diff --git a/man/okpi_yellow_light.Rd b/man/okpi_yellow_light.Rd new file mode 100644 index 0000000..1c0be4c --- /dev/null +++ b/man/okpi_yellow_light.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{okpi_yellow_light} +\alias{okpi_yellow_light} +\title{OKPI yellow light} +\format{ +An object of class \code{character} of length 1. +} +\usage{ +okpi_yellow_light +} +\description{ +OKPI yellow light +} +\keyword{datasets} diff --git a/man/okpi_yellow_palette.Rd b/man/okpi_yellow_palette.Rd new file mode 100644 index 0000000..9c450b5 --- /dev/null +++ b/man/okpi_yellow_palette.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\name{okpi_yellow_palette} +\alias{okpi_yellow_palette} +\title{OKPI Yellow palette} +\usage{ +okpi_yellow_palette(n) +} +\arguments{ +\item{n}{The number of colors to return} +} +\description{ +OKPI Yellow palette +} diff --git a/man/palette_ojo_cyan.Rd b/man/palette_ojo_cyan.Rd new file mode 100644 index 0000000..ed99c30 --- /dev/null +++ b/man/palette_ojo_cyan.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_cyan} +\alias{palette_ojo_cyan} +\title{OJO Cyan Palette} +\format{ +An object of class \code{character} of length 8. +} +\usage{ +palette_ojo_cyan +} +\description{ +OJO Cyan Palette +} +\details{ +A vector with hex-color codes for the OJO cyan palette. +} +\keyword{datasets} diff --git a/man/palette_ojo_diverging.Rd b/man/palette_ojo_diverging.Rd new file mode 100644 index 0000000..63ac65c --- /dev/null +++ b/man/palette_ojo_diverging.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_diverging} +\alias{palette_ojo_diverging} +\title{OJO Diverging Palette} +\format{ +An object of class \code{character} of length 8. +} +\usage{ +palette_ojo_diverging +} +\description{ +OJO Diverging Palette +} +\details{ +A vector with hex-color codes for the OJO diverging palette. +} +\keyword{datasets} diff --git a/man/palette_ojo_gray.Rd b/man/palette_ojo_gray.Rd new file mode 100644 index 0000000..b7d92c0 --- /dev/null +++ b/man/palette_ojo_gray.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_gray} +\alias{palette_ojo_gray} +\title{OJO Gray Palette} +\format{ +An object of class \code{character} of length 8. +} +\usage{ +palette_ojo_gray +} +\description{ +OJO Gray Palette +} +\details{ +A vector with hex-color codes for the OJO gray palette. +} +\keyword{datasets} diff --git a/man/palette_ojo_green.Rd b/man/palette_ojo_green.Rd new file mode 100644 index 0000000..167eef1 --- /dev/null +++ b/man/palette_ojo_green.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_green} +\alias{palette_ojo_green} +\title{OJO Green Palette} +\format{ +An object of class \code{character} of length 8. +} +\usage{ +palette_ojo_green +} +\description{ +OJO Green Palette +} +\details{ +A vector with hex-color codes for the OJO green palette. +} +\keyword{datasets} diff --git a/man/palette_ojo_magenta.Rd b/man/palette_ojo_magenta.Rd new file mode 100644 index 0000000..22c8dc3 --- /dev/null +++ b/man/palette_ojo_magenta.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_magenta} +\alias{palette_ojo_magenta} +\title{OJO Magenta Palette} +\format{ +An object of class \code{character} of length 8. +} +\usage{ +palette_ojo_magenta +} +\description{ +OJO Magenta Palette +} +\details{ +A vector with hex-color codes for the OJO magenta palette. +} +\keyword{datasets} diff --git a/man/palette_ojo_main.Rd b/man/palette_ojo_main.Rd new file mode 100644 index 0000000..37e9bb6 --- /dev/null +++ b/man/palette_ojo_main.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_main} +\alias{palette_ojo_main} +\title{OJO Main Palette} +\format{ +An object of class \code{character} of length 8. +} +\usage{ +palette_ojo_main +} +\description{ +OJO Main Palette +} +\keyword{datasets} diff --git a/man/palette_ojo_politics.Rd b/man/palette_ojo_politics.Rd new file mode 100644 index 0000000..eed3620 --- /dev/null +++ b/man/palette_ojo_politics.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_politics} +\alias{palette_ojo_politics} +\title{OJO Politics Palette} +\format{ +An object of class \code{character} of length 2. +} +\usage{ +palette_ojo_politics +} +\description{ +OJO Politics Palette +} +\details{ +A vector with hex-color codes for the OJO politics palette. +} +\keyword{datasets} diff --git a/man/palette_ojo_quintile.Rd b/man/palette_ojo_quintile.Rd new file mode 100644 index 0000000..e5bb69a --- /dev/null +++ b/man/palette_ojo_quintile.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_quintile} +\alias{palette_ojo_quintile} +\title{OJO Quintile Palette} +\format{ +An object of class \code{character} of length 5. +} +\usage{ +palette_ojo_quintile +} +\description{ +OJO Quintile Palette +} +\details{ +A vector with hex-color codes for the OJO quintile palette. +} +\keyword{datasets} diff --git a/man/palette_ojo_red.Rd b/man/palette_ojo_red.Rd new file mode 100644 index 0000000..e16fead --- /dev/null +++ b/man/palette_ojo_red.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_red} +\alias{palette_ojo_red} +\title{OJO Red Palette} +\format{ +An object of class \code{character} of length 8. +} +\usage{ +palette_ojo_red +} +\description{ +OJO Red Palette +} +\details{ +A vector with hex-color codes for the OJO red palette. +} +\keyword{datasets} diff --git a/man/palette_ojo_spacegray.Rd b/man/palette_ojo_spacegray.Rd new file mode 100644 index 0000000..caf857b --- /dev/null +++ b/man/palette_ojo_spacegray.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_spacegray} +\alias{palette_ojo_spacegray} +\title{OJO Space Gray Palette} +\format{ +An object of class \code{character} of length 8. +} +\usage{ +palette_ojo_spacegray +} +\description{ +OJO Space Gray Palette +} +\details{ +A vector with hex-color codes for the OJO space gray palette. +} +\keyword{datasets} diff --git a/man/palette_ojo_yellow.Rd b/man/palette_ojo_yellow.Rd new file mode 100644 index 0000000..e2cc442 --- /dev/null +++ b/man/palette_ojo_yellow.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_ojo_yellow} +\alias{palette_ojo_yellow} +\title{OJO Yellow Palette} +\format{ +An object of class \code{character} of length 8. +} +\usage{ +palette_ojo_yellow +} +\description{ +OJO Yellow Palette +} +\details{ +A vector with hex-color codes for the OJO yellow palette. +} +\keyword{datasets} diff --git a/man/palette_okpi_main.Rd b/man/palette_okpi_main.Rd new file mode 100644 index 0000000..83d8742 --- /dev/null +++ b/man/palette_okpi_main.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colors.R +\docType{data} +\name{palette_okpi_main} +\alias{palette_okpi_main} +\title{OKPI main palette} +\format{ +An object of class \code{character} of length 14. +} +\usage{ +palette_okpi_main +} +\description{ +OKPI Palettes +} +\details{ +A vector with hex-color codes that correspond to the extended color palette outlined in the Open Justice Oklahoma Data Visualization Style Guide. +\url{http://openjusticeok.github.io/styleguide/} +} +\keyword{datasets} diff --git a/man/tok_palettes.Rd b/man/palette_tok_main.Rd similarity index 93% rename from man/tok_palettes.Rd rename to man/palette_tok_main.Rd index 05f0351..deb7b45 100644 --- a/man/tok_palettes.Rd +++ b/man/palette_tok_main.Rd @@ -13,5 +13,4 @@ palette_tok_main \description{ TOK main palette } -\concept{tok palettes} \keyword{datasets} From 358caef7cd8322f4e31ec7ea4b3dfee9836abd6b Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Fri, 1 Nov 2024 14:33:53 -0500 Subject: [PATCH 09/25] added gt_ojo() and gt_okpi() functions --- DESCRIPTION | 19 ++--- NAMESPACE | 5 +- R/ojo_gt.R | 156 ++++++++++++++++++++++++++++++++++- R/ojo_labs.R | 70 ++++++++++++++-- man/gt_okpi.Rd | 45 ++++++++++ man/ojo_analyst_name_text.Rd | 17 ++++ man/ojo_gt.Rd | 26 ------ man/ojo_gt_captions.Rd | 18 ++++ man/ojo_source_text.Rd | 17 ++++ 9 files changed, 324 insertions(+), 49 deletions(-) create mode 100644 man/gt_okpi.Rd create mode 100644 man/ojo_analyst_name_text.Rd delete mode 100644 man/ojo_gt.Rd create mode 100644 man/ojo_gt_captions.Rd create mode 100644 man/ojo_source_text.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 729833c..5be91b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,17 +21,16 @@ Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 -Depends: Imports: - colorspace, - dplyr, - ggplot2, - gt, - gtExtras, - rlang, - showtext, - stringr, - sysfonts, + colorspace, + dplyr, + ggplot2, + gt, + rlang, + showtext, + stringr, + sysfonts, + tidyselect Suggests: ggrepel, testthat (>= 3.0.0) diff --git a/NAMESPACE b/NAMESPACE index 0ef77de..37cfd1e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,10 +8,13 @@ export(geom_path) export(geom_point) export(geom_step) export(geom_text) -export(ojo_gt) +export(gt_okpi) +export(ojo_analyst_name_text) +export(ojo_gt_captions) export(ojo_labs) export(ojo_make_caption) export(ojo_set_theme) +export(ojo_source_text) export(okpi_blue) export(okpi_blue_light) export(okpi_blue_palette) diff --git a/R/ojo_gt.R b/R/ojo_gt.R index bad2c06..1b844dc 100644 --- a/R/ojo_gt.R +++ b/R/ojo_gt.R @@ -1,18 +1,153 @@ -#' ojo_gt Function +#' gt_okpi Function #' #' @param data A data frame to be converted into a gt table. #' @param title Optional. A title for the table. Default is NA. #' @param subtitle Optional. A subtitle for the table. Default is NA. +#' @param font_size The font size for the table. Default is 14. +#' @param font The font family to use. Default is Roboto Condensed. +#' @param format_cols Should gt::fmt_auto() be applied to all cols? +#' @param analyst_name The name of the analyst to credit in the footnote +#' @param source The source / domain of the data +#' +#' @return A gt table based on the input data frame with specified modifications. +#' @examples +#' \dontrun{ +#' okpi_gt(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") +#' } +#' @export +gt_okpi <- function(data, + title = NA, subtitle = NA, + font_size = 14, + font = "Roboto Condensed", + format_cols = TRUE, + analyst_name = NA, source = NA + ) { + + x <- data |> + gt::gt() |> + gt::tab_options( + heading.align = "left", + column_labels.border.top.style = "none", + table.border.top.style = "none", + column_labels.border.bottom.style = "none", + column_labels.border.bottom.width = 1, + column_labels.border.bottom.color = "#A9A9A9", + table_body.border.top.style = "none", + table_body.border.bottom.color = "white", + heading.border.bottom.style = "none", + data_row.padding = gt::px(7), + column_labels.font.size = gt::px(font_size) + ) |> + gt::opt_table_font( + font = gt::google_font(font) + ) |> + gt::tab_style( + style = gt::cell_text(weight = "bold", + color = ojothemes::okpi_red, + size = gt::px(font_size * 2)), + locations = gt::cells_title(groups = "title") + ) |> + gt::tab_style( + style = gt::cell_text(style = "italic", + size = gt::px(font_size * 1.25)), + locations = gt::cells_title(groups = "subtitle") + ) |> + gt::tab_style( + style = gt::cell_text(color = "#A9A9A9", + transform = "uppercase"), + locations = gt::cells_column_labels(tidyselect::everything()) + ) |> + gt::tab_spanner( + label = stringr::str_to_title(colnames(data)) + ) |> + gt::tab_options( + column_labels.font.size = "medium", + table.font.size = "medium", + heading.title.font.size = "medium", + heading.subtitle.font.size = "small" + ) + + # Add title / subtitle? + if (!is.na(title) | !is.na(subtitle)) { + x <- x |> + gt::tab_header(title = title, + subtitle = subtitle) + } + + # Add col formatting? + if (format_cols) { + x <- x |> + gt::fmt_auto(lg_num_pref = "suf") + } + + if (!is.na(analyst_name) | !is.na(source)) { + x <- x |> + ojo_gt_captions(analyst_name = analyst_name, + source = source) + } + + return(x) +} + +#' gt_ojo Function +#' +#' @param data A data frame to be converted into a gt table. +#' @param title Optional. A title for the table. Default is NA. +#' @param subtitle Optional. A subtitle for the table. Default is NA. +#' @param font_size The font size for the table. Default is 14. +#' @param font The font family to use. Default is Roboto Condensed. +#' @param format_cols Should gt::fmt_auto() be applied to all cols? +#' @param analyst_name The name of the analyst to credit in the footnote +#' @param source The source / domain of the data +#' #' @return A gt table based on the input data frame with specified modifications. #' @examples #' \dontrun{ -#' ojo_gt(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") +#' okpi_gt(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") #' } #' @export -ojo_gt <- function(data, title = NA, subtitle = NA) { +gt_ojo <- function(data, + title = NA, subtitle = NA, + font_size = 14, + font = "Roboto Mono", + format_cols = TRUE, + analyst_name = NA, source = NA +) { + x <- data |> gt::gt() |> - gtExtras::gt_theme_nytimes() |> + gt::tab_options( + heading.align = "left", + column_labels.border.top.style = "none", + table.border.top.style = "none", + column_labels.border.bottom.style = "none", + column_labels.border.bottom.width = 1, + column_labels.border.bottom.color = "#A9A9A9", + table_body.border.top.style = "none", + table_body.border.bottom.color = "white", + heading.border.bottom.style = "none", + data_row.padding = gt::px(7), + column_labels.font.size = gt::px(font_size) + ) |> + gt::opt_table_font( + font = gt::google_font(font) + ) |> + gt::tab_style( + style = gt::cell_text(weight = "bold", + color = "#333333", + size = gt::px(font_size * 2)), + locations = gt::cells_title(groups = "title") + ) |> + gt::tab_style( + style = gt::cell_text(style = "italic", + size = gt::px(font_size * 1.25)), + locations = gt::cells_title(groups = "subtitle") + ) |> + gt::tab_style( + style = gt::cell_text(color = "#A9A9A9", + transform = "uppercase"), + locations = gt::cells_column_labels(tidyselect::everything()) + ) |> gt::tab_spanner( label = stringr::str_to_title(colnames(data)) ) |> @@ -30,5 +165,18 @@ ojo_gt <- function(data, title = NA, subtitle = NA) { subtitle = subtitle) } + # Add col formatting? + if (format_cols) { + x <- x |> + gt::fmt_auto(lg_num_pref = "suf") + } + + if (!is.na(analyst_name) | !is.na(source)) { + x <- x |> + ojo_gt_captions(analyst_name = analyst_name, + source = source) + } + return(x) } + diff --git a/R/ojo_labs.R b/R/ojo_labs.R index cf1922b..85cdf40 100644 --- a/R/ojo_labs.R +++ b/R/ojo_labs.R @@ -1,14 +1,11 @@ -#' OJO caption text +#' OJO source text #' @description -#' Creates the text for a caption to add to ggplots and gt tables, including consistent default "source: " statements. +#' A function to construct the "Source:" note text #' #' @param source The domain / source of the data. Can be one of "oscn", "ocdc", or "ppb" for canned text, NA for no source, or a custom string. -#' @param analyst_name The name of the analyst to credit -#' @returns A string with the caption text +#' @returns A string with the source text #' @export -ojo_make_caption <- function(analyst_name = NA, - source = NA){ - +ojo_source_text <- function(source = NA) { # Check that given source is in the list of options # Removed to allow for custom string # allowed_sources <- c("oscn", "ocdc", "ppb", NA) # source <- tolower(source) @@ -22,13 +19,39 @@ ojo_make_caption <- function(analyst_name = NA, is.na(source) ~ "", # If source = NA, just leave that out of the caption TRUE ~ source # If source is anything else, just print it verbatim ) + return(source_text) +} +#' OJO analyst name text +#' @description +#' A function to construct the analyst credit text +#' +#' @param analyst_name The name of the analyst to credit +#' @returns A string with the analyst credit text +#' @export +ojo_analyst_name_text <- function(analyst_name = NA) { # Construct the caption text (could build in analyst emails here too? i.e. "Chart created by Andrew Bell (abell@okpolicy.org)") analyst_name_text <- if(!is.na(analyst_name)){ - paste0("Chart created by ", analyst_name, ".") + paste0("Graphic created by ", analyst_name, ".") } else { "" } + return(analyst_name_text) +} + +#' OJO caption text +#' @description +#' Creates the text for a caption to add to ggplots and gt tables, including consistent default "source: " statements. +#' +#' @param source The domain / source of the data. Can be one of "oscn", "ocdc", or "ppb" for canned text, NA for no source, or a custom string. +#' @param analyst_name The name of the analyst to credit +#' @returns A string with the caption text +#' @export +ojo_make_caption <- function(analyst_name = NA, + source = NA){ + + source_text <- ojo_source_text(source = source) + analyst_name_text <- ojo_analyst_name_text(analyst_name = analyst_name) caption <- paste0(source_text, dplyr::if_else(!is.na(analyst_name) & !is.na(source), "\n", ""), # Add a newline if both are not NA @@ -60,3 +83,34 @@ ojo_labs <- function (..., ) } + +#' OJO gt caption / source note with defaults +#' @description +#' Wrapper for gt::tab_source_note() and gt::tab_footnote() with consistent defaults. +#' +#' @param x A gt object +#' @param analyst_name The name of the analyst to credit +#' @param source The data source / source of the data. +#' +#' @export +ojo_gt_captions <- function (x, + analyst_name = NA, + source = NA){ + + # Do we want to build any more QOL stuff into this? Like we could set it up + # so that it automatically decides when to display an axis label, formats + # those to be title case, etc. + x <- x |> + gt::tab_source_note( + source_note = ojo_source_text(source = source) + ) |> + gt::tab_footnote( + footnote = ojo_analyst_name_text(analyst_name = analyst_name) + ) |> + gt::tab_style( + style = gt::cell_text(align = "right"), + locations = list(gt::cells_source_notes(), gt::cells_footnotes()) + ) + + return(x) +} diff --git a/man/gt_okpi.Rd b/man/gt_okpi.Rd new file mode 100644 index 0000000..b38b690 --- /dev/null +++ b/man/gt_okpi.Rd @@ -0,0 +1,45 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ojo_gt.R +\name{gt_okpi} +\alias{gt_okpi} +\title{gt_okpi Function} +\usage{ +gt_okpi( + data, + title = NA, + subtitle = NA, + font_size = 14, + font = "Roboto Condensed", + format_cols = TRUE, + analyst_name = NA, + source = NA +) +} +\arguments{ +\item{data}{A data frame to be converted into a gt table.} + +\item{title}{Optional. A title for the table. Default is NA.} + +\item{subtitle}{Optional. A subtitle for the table. Default is NA.} + +\item{font_size}{The font size for the table. Default is 14.} + +\item{font}{The font family to use. Default is Roboto Condensed.} + +\item{format_cols}{Should gt::fmt_auto() be applied to all cols?} + +\item{analyst_name}{The name of the analyst to credit in the footnote} + +\item{source}{The source / domain of the data} +} +\value{ +A gt table based on the input data frame with specified modifications. +} +\description{ +gt_okpi Function +} +\examples{ +\dontrun{ +okpi_gt(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") +} +} diff --git a/man/ojo_analyst_name_text.Rd b/man/ojo_analyst_name_text.Rd new file mode 100644 index 0000000..16be42f --- /dev/null +++ b/man/ojo_analyst_name_text.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ojo_labs.R +\name{ojo_analyst_name_text} +\alias{ojo_analyst_name_text} +\title{OJO analyst name text} +\usage{ +ojo_analyst_name_text(analyst_name = NA) +} +\arguments{ +\item{analyst_name}{The name of the analyst to credit} +} +\value{ +A string with the analyst credit text +} +\description{ +A function to construct the analyst credit text +} diff --git a/man/ojo_gt.Rd b/man/ojo_gt.Rd deleted file mode 100644 index d671859..0000000 --- a/man/ojo_gt.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ojo_gt.R -\name{ojo_gt} -\alias{ojo_gt} -\title{ojo_gt Function} -\usage{ -ojo_gt(data, title = NA, subtitle = NA) -} -\arguments{ -\item{data}{A data frame to be converted into a gt table.} - -\item{title}{Optional. A title for the table. Default is NA.} - -\item{subtitle}{Optional. A subtitle for the table. Default is NA.} -} -\value{ -A gt table based on the input data frame with specified modifications. -} -\description{ -ojo_gt Function -} -\examples{ -\dontrun{ -ojo_gt(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") -} -} diff --git a/man/ojo_gt_captions.Rd b/man/ojo_gt_captions.Rd new file mode 100644 index 0000000..da0ec8b --- /dev/null +++ b/man/ojo_gt_captions.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ojo_labs.R +\name{ojo_gt_captions} +\alias{ojo_gt_captions} +\title{OJO gt caption / source note with defaults} +\usage{ +ojo_gt_captions(x, analyst_name = NA, source = NA) +} +\arguments{ +\item{x}{A gt object} + +\item{analyst_name}{The name of the analyst to credit} + +\item{source}{The data source / source of the data.} +} +\description{ +Wrapper for gt::tab_source_note() and gt::tab_footnote() with consistent defaults. +} diff --git a/man/ojo_source_text.Rd b/man/ojo_source_text.Rd new file mode 100644 index 0000000..39cce85 --- /dev/null +++ b/man/ojo_source_text.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ojo_labs.R +\name{ojo_source_text} +\alias{ojo_source_text} +\title{OJO source text} +\usage{ +ojo_source_text(source = NA) +} +\arguments{ +\item{source}{The domain / source of the data. Can be one of "oscn", "ocdc", or "ppb" for canned text, NA for no source, or a custom string.} +} +\value{ +A string with the source text +} +\description{ +A function to construct the "Source:" note text +} From 6a4172a6abf5676bf07150dc7eb0bd218daf5242 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:00:34 -0600 Subject: [PATCH 10/25] fixed zzz I think --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/ojo_gt.R | 36 +++++++++++++++++++++++++++--------- R/zzz.R | 14 -------------- man/gt_ojo.Rd | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 man/gt_ojo.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 5be91b3..e423014 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,7 @@ RoxygenNote: 7.3.2 Imports: colorspace, dplyr, - ggplot2, + ggplot2 (>= 3.0.0), gt, rlang, showtext, diff --git a/NAMESPACE b/NAMESPACE index 37cfd1e..a2ead15 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ export(geom_path) export(geom_point) export(geom_step) export(geom_text) +export(gt_ojo) export(gt_okpi) export(ojo_analyst_name_text) export(ojo_gt_captions) diff --git a/R/ojo_gt.R b/R/ojo_gt.R index 1b844dc..43c5621 100644 --- a/R/ojo_gt.R +++ b/R/ojo_gt.R @@ -42,14 +42,23 @@ gt_okpi <- function(data, font = gt::google_font(font) ) |> gt::tab_style( - style = gt::cell_text(weight = "bold", - color = ojothemes::okpi_red, - size = gt::px(font_size * 2)), + style = list( + gt::cell_text(weight = "bold", + color = ojothemes::okpi_red, + size = gt::px(font_size * 2)), + gt::css(padding.left = "10px", + border.left = paste0("10px solid ", okpi_red, ";")) + ), locations = gt::cells_title(groups = "title") ) |> gt::tab_style( - style = gt::cell_text(style = "italic", - size = gt::px(font_size * 1.25)), + style = list( + gt::cell_text(style = "italic", + color = ojothemes::okpi_blue, + size = gt::px(font_size * 1.25)), + gt::css(padding.left = "10px", + border.left = paste0("10px solid ", okpi_red, ";")) + ), locations = gt::cells_title(groups = "subtitle") ) |> gt::tab_style( @@ -133,14 +142,23 @@ gt_ojo <- function(data, font = gt::google_font(font) ) |> gt::tab_style( - style = gt::cell_text(weight = "bold", - color = "#333333", - size = gt::px(font_size * 2)), + style = list( + gt::cell_text(weight = "bold", + color = "#333333", + size = gt::px(font_size * 2)), + # I think this little splash of color is nice + gt::css(padding.left = "10px", + border.left = paste0("10px solid ", okpi_yellow, ";")) + ), locations = gt::cells_title(groups = "title") ) |> gt::tab_style( - style = gt::cell_text(style = "italic", + style = list( + gt::cell_text(style = "italic", size = gt::px(font_size * 1.25)), + gt::css(padding.left = "10px", + border.left = paste0("10px solid ", okpi_yellow, ";")) + ), locations = gt::cells_title(groups = "subtitle") ) |> gt::tab_style( diff --git a/R/zzz.R b/R/zzz.R index b710a63..6ede1a8 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -19,18 +19,4 @@ sysfonts::font_add_google("Roboto Condensed") showtext::showtext_auto() - # check ggplot2 version - if (unlist(utils::packageVersion("ggplot2"))[1] < 3) { - packageStartupMessage( - "Warning: ojothemes requires ggplot2 version 3.0.0 or higher." - ) - } - - # check that ggplot2 is already loaded - if (!"ggplot2" %in% (.packages())) { - packageStartupMessage( - "Warning: ggplot2 needs to be loaded before ojothemes is loaded. Consider restarting your R session." - ) - } - } diff --git a/man/gt_ojo.Rd b/man/gt_ojo.Rd new file mode 100644 index 0000000..2fc60cb --- /dev/null +++ b/man/gt_ojo.Rd @@ -0,0 +1,45 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ojo_gt.R +\name{gt_ojo} +\alias{gt_ojo} +\title{gt_ojo Function} +\usage{ +gt_ojo( + data, + title = NA, + subtitle = NA, + font_size = 14, + font = "Roboto Mono", + format_cols = TRUE, + analyst_name = NA, + source = NA +) +} +\arguments{ +\item{data}{A data frame to be converted into a gt table.} + +\item{title}{Optional. A title for the table. Default is NA.} + +\item{subtitle}{Optional. A subtitle for the table. Default is NA.} + +\item{font_size}{The font size for the table. Default is 14.} + +\item{font}{The font family to use. Default is Roboto Condensed.} + +\item{format_cols}{Should gt::fmt_auto() be applied to all cols?} + +\item{analyst_name}{The name of the analyst to credit in the footnote} + +\item{source}{The source / domain of the data} +} +\value{ +A gt table based on the input data frame with specified modifications. +} +\description{ +gt_ojo Function +} +\examples{ +\dontrun{ +okpi_gt(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") +} +} From 61658f10b98d9b6abc4c102245ef90a26186fbb7 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:59:51 -0600 Subject: [PATCH 11/25] split the gt themes out into gt_base and _ojo _okpi versions --- NAMESPACE | 1 + R/ojo_gt.R | 168 ++++++++++++++++++++++++------------------------- R/ojo_labs.R | 1 + man/gt_base.Rd | 42 +++++++++++++ man/gt_ojo.Rd | 2 +- 5 files changed, 126 insertions(+), 88 deletions(-) create mode 100644 man/gt_base.Rd diff --git a/NAMESPACE b/NAMESPACE index a2ead15..7fabc52 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ export(geom_path) export(geom_point) export(geom_step) export(geom_text) +export(gt_base) export(gt_ojo) export(gt_okpi) export(ojo_analyst_name_text) diff --git a/R/ojo_gt.R b/R/ojo_gt.R index 43c5621..5befc74 100644 --- a/R/ojo_gt.R +++ b/R/ojo_gt.R @@ -1,10 +1,9 @@ -#' gt_okpi Function +#' gt_base Function #' #' @param data A data frame to be converted into a gt table. #' @param title Optional. A title for the table. Default is NA. #' @param subtitle Optional. A subtitle for the table. Default is NA. #' @param font_size The font size for the table. Default is 14. -#' @param font The font family to use. Default is Roboto Condensed. #' @param format_cols Should gt::fmt_auto() be applied to all cols? #' @param analyst_name The name of the analyst to credit in the footnote #' @param source The source / domain of the data @@ -12,17 +11,16 @@ #' @return A gt table based on the input data frame with specified modifications. #' @examples #' \dontrun{ -#' okpi_gt(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") +#' gt_base(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") #' } #' @export -gt_okpi <- function(data, - title = NA, subtitle = NA, - font_size = 14, - font = "Roboto Condensed", - format_cols = TRUE, - analyst_name = NA, source = NA - ) { - +#' +gt_base <- function(data, + title = NA, subtitle = NA, + font_size = 14, + format_cols = TRUE, + analyst_name = NA, source = NA +){ x <- data |> gt::gt() |> gt::tab_options( @@ -38,34 +36,6 @@ gt_okpi <- function(data, data_row.padding = gt::px(7), column_labels.font.size = gt::px(font_size) ) |> - gt::opt_table_font( - font = gt::google_font(font) - ) |> - gt::tab_style( - style = list( - gt::cell_text(weight = "bold", - color = ojothemes::okpi_red, - size = gt::px(font_size * 2)), - gt::css(padding.left = "10px", - border.left = paste0("10px solid ", okpi_red, ";")) - ), - locations = gt::cells_title(groups = "title") - ) |> - gt::tab_style( - style = list( - gt::cell_text(style = "italic", - color = ojothemes::okpi_blue, - size = gt::px(font_size * 1.25)), - gt::css(padding.left = "10px", - border.left = paste0("10px solid ", okpi_red, ";")) - ), - locations = gt::cells_title(groups = "subtitle") - ) |> - gt::tab_style( - style = gt::cell_text(color = "#A9A9A9", - transform = "uppercase"), - locations = gt::cells_column_labels(tidyselect::everything()) - ) |> gt::tab_spanner( label = stringr::str_to_title(colnames(data)) ) |> @@ -74,8 +44,15 @@ gt_okpi <- function(data, table.font.size = "medium", heading.title.font.size = "medium", heading.subtitle.font.size = "small" + ) |> + gt::tab_style( + style = gt::cell_text(color = "#333333", + transform = "uppercase", + weight = "bold"), + locations = gt::cells_column_labels(tidyselect::everything()) ) + # Add title / subtitle? if (!is.na(title) | !is.na(subtitle)) { x <- x |> @@ -98,7 +75,7 @@ gt_okpi <- function(data, return(x) } -#' gt_ojo Function +#' gt_okpi Function #' #' @param data A data frame to be converted into a gt table. #' @param title Optional. A title for the table. Default is NA. @@ -115,6 +92,64 @@ gt_okpi <- function(data, #' okpi_gt(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") #' } #' @export +gt_okpi <- function(data, + title = NA, subtitle = NA, + font_size = 14, + font = "Roboto Condensed", + format_cols = TRUE, + analyst_name = NA, source = NA){ + + x <- data |> + ojothemes::gt_base(title = title, + subtitle = subtitle, + font_size = font_size, + format_cols = format_cols, + analyst_name = analyst_name, + source = source) |> + gt::opt_table_font( + font = gt::google_font(font) + ) |> + gt::tab_style( + style = list( + gt::cell_text(weight = "bold", + color = ojothemes::okpi_red, + size = gt::px(font_size * 2)), + gt::css(padding.left = "10px", + border.left = paste0("10px solid ", okpi_red, ";")) + ), + locations = gt::cells_title(groups = "title") + ) |> + gt::tab_style( + style = list( + gt::cell_text(style = "italic", + color = "#333333", + size = gt::px(font_size * 1.25)), + gt::css(padding.left = "10px", + border.left = paste0("10px solid ", okpi_red, ";")) + ), + locations = gt::cells_title(groups = "subtitle") + ) + + return(x) +} + +#' gt_ojo Function +#' +#' @param data A data frame to be converted into a gt table. +#' @param title Optional. A title for the table. Default is NA. +#' @param subtitle Optional. A subtitle for the table. Default is NA. +#' @param font_size The font size for the table. Default is 14. +#' @param font The font family to use. Default is Roboto mono +#' @param format_cols Should gt::fmt_auto() be applied to all cols? +#' @param analyst_name The name of the analyst to credit in the footnote +#' @param source The source / domain of the data +#' +#' @return A gt table based on the input data frame with specified modifications. +#' @examples +#' \dontrun{ +#' okpi_gt(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") +#' } +#' @export gt_ojo <- function(data, title = NA, subtitle = NA, font_size = 14, @@ -124,20 +159,12 @@ gt_ojo <- function(data, ) { x <- data |> - gt::gt() |> - gt::tab_options( - heading.align = "left", - column_labels.border.top.style = "none", - table.border.top.style = "none", - column_labels.border.bottom.style = "none", - column_labels.border.bottom.width = 1, - column_labels.border.bottom.color = "#A9A9A9", - table_body.border.top.style = "none", - table_body.border.bottom.color = "white", - heading.border.bottom.style = "none", - data_row.padding = gt::px(7), - column_labels.font.size = gt::px(font_size) - ) |> + ojothemes::gt_base(title = title, + subtitle = subtitle, + font_size = font_size, + format_cols = format_cols, + analyst_name = analyst_name, + source = source) |> gt::opt_table_font( font = gt::google_font(font) ) |> @@ -160,41 +187,8 @@ gt_ojo <- function(data, border.left = paste0("10px solid ", okpi_yellow, ";")) ), locations = gt::cells_title(groups = "subtitle") - ) |> - gt::tab_style( - style = gt::cell_text(color = "#A9A9A9", - transform = "uppercase"), - locations = gt::cells_column_labels(tidyselect::everything()) - ) |> - gt::tab_spanner( - label = stringr::str_to_title(colnames(data)) - ) |> - gt::tab_options( - column_labels.font.size = "medium", - table.font.size = "medium", - heading.title.font.size = "medium", - heading.subtitle.font.size = "small" ) - # Add title / subtitle? - if (!is.na(title) | !is.na(subtitle)) { - x <- x |> - gt::tab_header(title = title, - subtitle = subtitle) - } - - # Add col formatting? - if (format_cols) { - x <- x |> - gt::fmt_auto(lg_num_pref = "suf") - } - - if (!is.na(analyst_name) | !is.na(source)) { - x <- x |> - ojo_gt_captions(analyst_name = analyst_name, - source = source) - } - return(x) } diff --git a/R/ojo_labs.R b/R/ojo_labs.R index 85cdf40..afd21f5 100644 --- a/R/ojo_labs.R +++ b/R/ojo_labs.R @@ -16,6 +16,7 @@ ojo_source_text <- function(source = NA) { source == "oscn" ~ "Source: OK Policy Institute analysis of Oklahoma State Courts Network data.", source == "ocdc" ~ "Source: OK Policy Institute analysis of data from the Oklahoma County Detention Center's 'Jailtracker' system.", source == "ppb" ~ "Source: OK Policy Institute analysis of Oklahoma Pardon and Parole Board records.", + # TODO: add OJA is.na(source) ~ "", # If source = NA, just leave that out of the caption TRUE ~ source # If source is anything else, just print it verbatim ) diff --git a/man/gt_base.Rd b/man/gt_base.Rd new file mode 100644 index 0000000..07a819b --- /dev/null +++ b/man/gt_base.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ojo_gt.R +\name{gt_base} +\alias{gt_base} +\title{gt_base Function} +\usage{ +gt_base( + data, + title = NA, + subtitle = NA, + font_size = 14, + format_cols = TRUE, + analyst_name = NA, + source = NA +) +} +\arguments{ +\item{data}{A data frame to be converted into a gt table.} + +\item{title}{Optional. A title for the table. Default is NA.} + +\item{subtitle}{Optional. A subtitle for the table. Default is NA.} + +\item{font_size}{The font size for the table. Default is 14.} + +\item{format_cols}{Should gt::fmt_auto() be applied to all cols?} + +\item{analyst_name}{The name of the analyst to credit in the footnote} + +\item{source}{The source / domain of the data} +} +\value{ +A gt table based on the input data frame with specified modifications. +} +\description{ +gt_base Function +} +\examples{ +\dontrun{ +gt_base(data = mtcars, title = "Motor Trend Car Road Tests", subtitle = "From mtcars") +} +} diff --git a/man/gt_ojo.Rd b/man/gt_ojo.Rd index 2fc60cb..ba67a18 100644 --- a/man/gt_ojo.Rd +++ b/man/gt_ojo.Rd @@ -24,7 +24,7 @@ gt_ojo( \item{font_size}{The font size for the table. Default is 14.} -\item{font}{The font family to use. Default is Roboto Condensed.} +\item{font}{The font family to use. Default is Roboto mono} \item{format_cols}{Should gt::fmt_auto() be applied to all cols?} From 61dd372f0f19ccd590e2ab7b4da596ddbdfe02b6 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Thu, 7 Nov 2024 15:04:58 -0600 Subject: [PATCH 12/25] improved gt_base --- R/ojo_gt.R | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/R/ojo_gt.R b/R/ojo_gt.R index 5befc74..8a34648 100644 --- a/R/ojo_gt.R +++ b/R/ojo_gt.R @@ -50,6 +50,21 @@ gt_base <- function(data, transform = "uppercase", weight = "bold"), locations = gt::cells_column_labels(tidyselect::everything()) + ) |> + gt::tab_style( + style = list( + gt::cell_text(weight = "bold", + size = gt::px(font_size * 2)) + ), + locations = gt::cells_title(groups = "title") + ) |> + gt::tab_style( + style = list( + gt::cell_text(style = "italic", + color = "#333333", + size = gt::px(font_size * 1.25)) + ), + locations = gt::cells_title(groups = "subtitle") ) @@ -111,9 +126,7 @@ gt_okpi <- function(data, ) |> gt::tab_style( style = list( - gt::cell_text(weight = "bold", - color = ojothemes::okpi_red, - size = gt::px(font_size * 2)), + gt::cell_text(color = ojothemes::okpi_red), gt::css(padding.left = "10px", border.left = paste0("10px solid ", okpi_red, ";")) ), @@ -121,9 +134,6 @@ gt_okpi <- function(data, ) |> gt::tab_style( style = list( - gt::cell_text(style = "italic", - color = "#333333", - size = gt::px(font_size * 1.25)), gt::css(padding.left = "10px", border.left = paste0("10px solid ", okpi_red, ";")) ), @@ -170,10 +180,6 @@ gt_ojo <- function(data, ) |> gt::tab_style( style = list( - gt::cell_text(weight = "bold", - color = "#333333", - size = gt::px(font_size * 2)), - # I think this little splash of color is nice gt::css(padding.left = "10px", border.left = paste0("10px solid ", okpi_yellow, ";")) ), @@ -181,8 +187,6 @@ gt_ojo <- function(data, ) |> gt::tab_style( style = list( - gt::cell_text(style = "italic", - size = gt::px(font_size * 1.25)), gt::css(padding.left = "10px", border.left = paste0("10px solid ", okpi_yellow, ";")) ), From 3d7cdd111f1cdcab9e094d47c314f37a4952b452 Mon Sep 17 00:00:00 2001 From: Brancen Gregory Date: Tue, 12 Nov 2024 12:24:08 -0600 Subject: [PATCH 13/25] Add pkgdown --- .Rbuildignore | 3 +++ .github/workflows/pkgdown.yaml | 49 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + DESCRIPTION | 1 + _pkgdown.yml | 4 +++ 5 files changed, 58 insertions(+) create mode 100644 .github/workflows/pkgdown.yaml create mode 100644 _pkgdown.yml diff --git a/.Rbuildignore b/.Rbuildignore index f86d7bb..15c8ff7 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -4,3 +4,6 @@ ^README\.Rmd$ ^cran-comments\.md$ ^\.github$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..bfc9f4d --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,49 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + release: + types: [published] + workflow_dispatch: + +name: pkgdown.yaml + +permissions: read-all + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.gitignore b/.gitignore index 353c119..ea0c3d7 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ vignettes/*.pdf .Renviron ======= .Rproj.user +docs diff --git a/DESCRIPTION b/DESCRIPTION index e423014..bb984ef 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,3 +35,4 @@ Suggests: ggrepel, testthat (>= 3.0.0) Config/testthat/edition: 3 +URL: https://openjusticeok.github.io/ojothemes/ diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..9fe7154 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: https://openjusticeok.github.io/ojothemes/ +template: + bootstrap: 5 + From 9d031b8ea759857e27a2b65f4bf2b7fff33bfde7 Mon Sep 17 00:00:00 2001 From: Brancen Gregory Date: Tue, 12 Nov 2024 12:32:50 -0600 Subject: [PATCH 14/25] Init testthat and vdiffr --- DESCRIPTION | 5 +++-- tests/testthat.R | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bb984ef..2fea378 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,7 +32,8 @@ Imports: sysfonts, tidyselect Suggests: - ggrepel, - testthat (>= 3.0.0) + ggrepel, + testthat (>= 3.0.0), + vdiffr Config/testthat/edition: 3 URL: https://openjusticeok.github.io/ojothemes/ diff --git a/tests/testthat.R b/tests/testthat.R index b475d7c..01d2cf1 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,12 @@ -# library(testthat) -# library(ojothemes) +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. # -# test_check("ojothemes") +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(ojothemes) + +test_check("ojothemes") From 8f4a04128338e71adf78c54d2bf0fc250c43ed11 Mon Sep 17 00:00:00 2001 From: Brancen Gregory Date: Tue, 12 Nov 2024 13:58:12 -0600 Subject: [PATCH 15/25] Add namespacing; replace argument name in element_line and element_rect due to deprecation; add basic vdiffr snapshot tests --- R/geoms.R | 2 +- R/theme_ojo.R | 10 +-- R/theme_okpi.R | 4 +- tests/testthat/_snaps/ojo_gt/demo-ojo-gt.svg | 0 .../_snaps/theme_okpi/demo-theme-okpi.svg | 88 +++++++++++++++++++ tests/testthat/test-ojo_gt.R | 18 ++++ tests/testthat/test-theme_okpi.R | 18 ++++ 7 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 tests/testthat/_snaps/ojo_gt/demo-ojo-gt.svg create mode 100644 tests/testthat/_snaps/theme_okpi/demo-theme-okpi.svg create mode 100644 tests/testthat/test-ojo_gt.R create mode 100644 tests/testthat/test-theme_okpi.R diff --git a/R/geoms.R b/R/geoms.R index 4237235..70542e6 100644 --- a/R/geoms.R +++ b/R/geoms.R @@ -20,7 +20,7 @@ GeomColOJO <- ggplot2::ggproto( draw_panel = function(self, data, panel_params, coord, width = NULL) { # Hack to ensure that width is detected as a parameter - ggplot2::ggproto_parent(GeomRect, self)$draw_panel(data, panel_params, coord) + ggplot2::ggproto_parent(ggplot2::GeomRect, self)$draw_panel(data, panel_params, coord) } ) diff --git a/R/theme_ojo.R b/R/theme_ojo.R index 2f36a9f..94d146f 100644 --- a/R/theme_ojo.R +++ b/R/theme_ojo.R @@ -16,12 +16,12 @@ theme_ojo_base <- function(base_size = 16, ggplot2::theme( line = ggplot2::element_line(colour = "#000000", - size = base_line_size, + linewidth = base_line_size, linetype = 1L, lineend = "butt"), rect = ggplot2::element_rect(fill = "#FFFFFF", colour = "#000000", - size = base_rect_size, + linewidth = base_rect_size, linetype = 1L), text = ggplot2::element_text(family = base_family, face = "plain", @@ -85,14 +85,14 @@ theme_ojo_base <- function(base_size = 16, axis.ticks = ggplot2::element_line(), axis.ticks.length = ggplot2::unit(4L, "pt"), axis.ticks.x = ggplot2::element_line(colour = NULL, - size = NULL, + linewidth = NULL, linetype = NULL, lineend = NULL), axis.ticks.y = ggplot2::element_blank(), axis.line = ggplot2::element_line(), axis.line.x = ggplot2::element_line(colour = NULL, - size = NULL, + linewidth = NULL, linetype = NULL, lineend = NULL), axis.line.y = ggplot2::element_blank(), @@ -142,7 +142,7 @@ theme_ojo_base <- function(base_size = 16, # strip attributes (Faceting) strip.background = ggplot2::element_rect(fill = "#dedddd", colour = NA, - size = 10L), + linewidth = 10L), strip.text = ggplot2::element_text(face = "bold", size = base_size * 9.5 / 8.5, margin = ggplot2::margin(t = 0L, r = 0L, b = 0L, l = 0L)), diff --git a/R/theme_okpi.R b/R/theme_okpi.R index 478e211..2c05b7c 100644 --- a/R/theme_okpi.R +++ b/R/theme_okpi.R @@ -16,12 +16,12 @@ theme_okpi_base <- function(base_size = 16, ggplot2::theme( line = ggplot2::element_line(colour = "#333333", - size = base_line_size, + linewidth = base_line_size, linetype = 1L, lineend = "butt"), rect = ggplot2::element_rect(fill = "#ffffff", colour = NA, - size = base_rect_size, + linewidth = base_rect_size, linetype = 1L), text = ggplot2::element_text(family = base_family, face = "plain", diff --git a/tests/testthat/_snaps/ojo_gt/demo-ojo-gt.svg b/tests/testthat/_snaps/ojo_gt/demo-ojo-gt.svg new file mode 100644 index 0000000..e69de29 diff --git a/tests/testthat/_snaps/theme_okpi/demo-theme-okpi.svg b/tests/testthat/_snaps/theme_okpi/demo-theme-okpi.svg new file mode 100644 index 0000000..f07c4b4 --- /dev/null +++ b/tests/testthat/_snaps/theme_okpi/demo-theme-okpi.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testthat/test-ojo_gt.R b/tests/testthat/test-ojo_gt.R new file mode 100644 index 0000000..21d18a5 --- /dev/null +++ b/tests/testthat/test-ojo_gt.R @@ -0,0 +1,18 @@ +test_that("gt_okpi style is consistent", { + data <- tibble::tibble( + county = c("Tulsa", "Oklahoma"), + variable1 = c(95, 85), + variable2 = c(4.25, 3.12), + variable3 = c("factor1", "factor2") + ) + + vdiffr::expect_doppelganger("demo-ojo_gt", { + gt_okpi( + data, + title = "A demo table", + subtitle = "Towards beauty in our tables", + analyst_name = "Brancen Gregory", + source = ojo_source_text("oscn") + ) + }) +}) diff --git a/tests/testthat/test-theme_okpi.R b/tests/testthat/test-theme_okpi.R new file mode 100644 index 0000000..fd4ae8c --- /dev/null +++ b/tests/testthat/test-theme_okpi.R @@ -0,0 +1,18 @@ +test_that("theme_okpi is stable", { + data <- tibble::tibble( + county = c("Tulsa", "Oklahoma"), + variable1 = c(95, 85), + variable2 = c(4.25, 3.12), + variable3 = c("factor1", "factor2") + ) + + vdiffr::expect_doppelganger("demo-theme_okpi", { + ojo_set_theme() + + ggplot2::ggplot( + data, + ggplot2::aes(x = variable1, y = variable2, group = variable3) + ) + + geom_col() + }) +}) From 204aa27d3f3d7341128c00b3ee0f01b5f508ff4d Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:56:06 -0600 Subject: [PATCH 16/25] adding tibble to suggests to get rid of a note on devtools::check() --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 2fea378..6a2e703 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,6 +34,7 @@ Imports: Suggests: ggrepel, testthat (>= 3.0.0), + tibble, vdiffr Config/testthat/edition: 3 URL: https://openjusticeok.github.io/ojothemes/ From 7d2b7e7ea7f8573c9c60523cdb7766c1fa22eddc Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:51:53 -0600 Subject: [PATCH 17/25] vignette --- .gitignore | 1 + DESCRIPTION | 3 + vignettes/.gitignore | 2 + vignettes/ojothemes-vignette.Rmd | 122 +++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 vignettes/.gitignore create mode 100644 vignettes/ojothemes-vignette.Rmd diff --git a/.gitignore b/.gitignore index ea0c3d7..c962d89 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ vignettes/*.pdf ======= .Rproj.user docs +inst/doc diff --git a/DESCRIPTION b/DESCRIPTION index 6a2e703..249ca86 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,8 +33,11 @@ Imports: tidyselect Suggests: ggrepel, + knitr, + rmarkdown, testthat (>= 3.0.0), tibble, vdiffr Config/testthat/edition: 3 URL: https://openjusticeok.github.io/ojothemes/ +VignetteBuilder: knitr diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/ojothemes-vignette.Rmd b/vignettes/ojothemes-vignette.Rmd new file mode 100644 index 0000000..d7ca606 --- /dev/null +++ b/vignettes/ojothemes-vignette.Rmd @@ -0,0 +1,122 @@ +--- +title: "ojoThemes Guide" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{ojothemes-vignette} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +This guide will walk you through the themes and tools available in the `ojoThemes` package. We'll start by loading the package (plus `tidyverse` and `ojodb` for some test data), then we'll make some example graphs and tables to show you what's available. + +```{r setup} +library(ojothemes) +library(ojodb) +library(tidyverse) +library(gt) + +# Test data from OCDC +data <- ojo_tbl(schema = "ocdc", + table = "arrest") |> + filter(book_date >= "01-01-2024", + book_date < "11-01-2024") |> + ojo_collect() + +``` +## Themes for `ggplot` graphs + +First, let's see how this data looks on a default ggplot: + +```{r default_ggplot} +p1 <- data |> + # We'll look at the bookings by race here, + # and we'll look by month just to make it easier to see. + mutate(book_month = floor_date(book_date, "months")) |> + count(book_month, race) |> + ggplot(aes(x = book_month, y = n, fill = race)) + + geom_col() + +p1 +``` + +Next, let's gussy this up with our `ojoThemes` tools. First, let's use the `ojothemes::ojo_labs()` function to easily add a nice caption to the plot: + +```{r ojo_labs} +p1 <- p1 + + ojo_labs(analyst_name = "Andrew Bell", + source = "ocdc", + title = "OCDC Bookings by Race", + subtitle = "January 2024 - October 2024", + x = "Month", + y = "Total Booking Events") + +p1 +``` + +This is just a wrapper for the normal `ggplot2::labs()` function, so we can pass arguments like `title`, `subtitle`, `x`, and `y` to it. The really neat thing, though, is the new `analyst_name` and `source` arguments. These will add a nice little "Graphic created by..." caption crediting the analyst, and a consistently phrased note on where the data came from. + + * Right now, you can use `"oscn"`, `"ocdc"`, or `"ppb"` as the `source` argument to get a pre-written, consistent source note. However, if you're working with something not in one of those domains, you can just tell it something to put in there verbatim, e.g. `source = "Source: Data Pulled from The National Insitute of My Ass database"`. + +Next, let's actually apply our themes. There are two ways to do this: the first is to just throw `+ theme_okpi()` onto our ggplot, like so: + +```{r plus_theme_okpi} +p1 + theme_okpi() +``` + +This applies not just the theme / fonts, but the color / fill scales as well. If you want just the theme without the scales, you can do `p1 + theme_okpi_base()`. + +The second way of applying a theme is by using `ojothemes::ojo_set_theme()`. This is probably going to be the most common way of doing things, since we're rarely going to want to use multiple themes in the same script / document / etc. Let's try that same graph in the "ojo" theme this time: + +```{r set_theme_okpi} +ojo_set_theme(theme = "ojo") + +p1 +``` + +## Themes for `gt` tables + +This package also has built in themes for tables made with `gt`. You can use these by replacing the normal `gt()` function with one of our themed wrappers (currently `gt_okpi()` and `gt_ojo()`). These have built in arguments for customization: + + * `source` and `analyst_name` (which work just like the `ojo_labs()` function for ggplots) + * `title` and `subtitle` (self explanatory) + * `format_cols` (a logical that will apply the auto-styling from `gt` to every column if `TRUE`) + * `font` and `font_size` for making really big / small tables. + +Here's what a normal, unstyled table looks like... + +```{r gt} +data |> + count(race) |> + gt() +``` + +...here's what our `gt_okpi()` theme does to it... + +```{r gt_okpi} +data |> + count(race) |> + gt_okpi(title = "OCDC Bookings by Race", + subtitle = "January 2024 - October 2024", + source = "ocdc", + analyst_name = "Andrew Bell", + format_cols = TRUE) +``` + +...and finally, here's `gt_ojo()`: + +```{r gt_ojo} +data |> + count(race) |> + gt_ojo(title = "OCDC Bookings by Race", + subtitle = "January 2024 - October 2024", + source = "ocdc", + analyst_name = "Andrew Bell", + format_cols = TRUE) +``` From 9c69b34caa477dc9528ebaca5d9a1de4a1c4ad89 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:55:32 -0600 Subject: [PATCH 18/25] fixed typo --- vignettes/ojothemes-vignette.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vignettes/ojothemes-vignette.Rmd b/vignettes/ojothemes-vignette.Rmd index d7ca606..f96a1ce 100644 --- a/vignettes/ojothemes-vignette.Rmd +++ b/vignettes/ojothemes-vignette.Rmd @@ -38,8 +38,8 @@ First, let's see how this data looks on a default ggplot: p1 <- data |> # We'll look at the bookings by race here, # and we'll look by month just to make it easier to see. - mutate(book_month = floor_date(book_date, "months")) |> - count(book_month, race) |> + count(book_month = floor_date(book_date, "months"), + race) |> ggplot(aes(x = book_month, y = n, fill = race)) + geom_col() From 8b97ad5762242138aece50b96c40ab6b83774b4b Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:09:54 -0600 Subject: [PATCH 19/25] fix dependancy bs --- DESCRIPTION | 1 + vignettes/ojothemes-vignette.Rmd | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 249ca86..3316c05 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,6 +34,7 @@ Imports: Suggests: ggrepel, knitr, + ojodb, rmarkdown, testthat (>= 3.0.0), tibble, diff --git a/vignettes/ojothemes-vignette.Rmd b/vignettes/ojothemes-vignette.Rmd index f96a1ce..66f66e0 100644 --- a/vignettes/ojothemes-vignette.Rmd +++ b/vignettes/ojothemes-vignette.Rmd @@ -19,7 +19,9 @@ This guide will walk you through the themes and tools available in the `ojoTheme ```{r setup} library(ojothemes) library(ojodb) -library(tidyverse) +library(dplyr) +library(ggplot2) +library(lubridate) library(gt) # Test data from OCDC From d1fc738b3ab0fbe8ad758e868e96e7689079304f Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:22:24 -0600 Subject: [PATCH 20/25] add renv --- .Rbuildignore | 2 + .Rprofile | 1 + renv.lock | 925 +++++++++++++++++++++++++++++++++ renv/.gitignore | 7 + renv/activate.R | 1220 ++++++++++++++++++++++++++++++++++++++++++++ renv/settings.json | 19 + 6 files changed, 2174 insertions(+) create mode 100644 .Rprofile create mode 100644 renv.lock create mode 100644 renv/.gitignore create mode 100644 renv/activate.R create mode 100644 renv/settings.json diff --git a/.Rbuildignore b/.Rbuildignore index 15c8ff7..251fb9a 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,5 @@ +^renv$ +^renv\.lock$ ^ojothemes\.Rproj$ ^\.Rproj\.user$ ^LICENSE\.md$ diff --git a/.Rprofile b/.Rprofile new file mode 100644 index 0000000..81b960f --- /dev/null +++ b/.Rprofile @@ -0,0 +1 @@ +source("renv/activate.R") diff --git a/renv.lock b/renv.lock new file mode 100644 index 0000000..afc5771 --- /dev/null +++ b/renv.lock @@ -0,0 +1,925 @@ +{ + "R": { + "Version": "4.4.1", + "Repositories": [ + { + "Name": "CRAN", + "URL": "https://cloud.r-project.org" + } + ] + }, + "Packages": { + "MASS": { + "Package": "MASS", + "Version": "7.3-61", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "methods", + "stats", + "utils" + ], + "Hash": "0cafd6f0500e5deba33be22c46bf6055" + }, + "Matrix": { + "Package": "Matrix", + "Version": "1.7-0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "grid", + "lattice", + "methods", + "stats", + "utils" + ], + "Hash": "1920b2f11133b12350024297d8a4ff4a" + }, + "R6": { + "Package": "R6", + "Version": "2.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "470851b6d5d0ac559e9d01bb352b4021" + }, + "RColorBrewer": { + "Package": "RColorBrewer", + "Version": "1.1-3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "45f0398006e83a5b10b72a90663d8d8c" + }, + "Rcpp": { + "Package": "Rcpp", + "Version": "1.0.13-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "methods", + "utils" + ], + "Hash": "6b868847b365672d6c1677b1608da9ed" + }, + "V8": { + "Package": "V8", + "Version": "6.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Rcpp", + "curl", + "jsonlite", + "utils" + ], + "Hash": "6603bfcbc7883a5fed41fb13042a3899" + }, + "base64enc": { + "Package": "base64enc", + "Version": "0.1-3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "543776ae6848fde2f48ff3816d0628bc" + }, + "bigD": { + "Package": "bigD", + "Version": "0.2.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "93637e906f3fe962413912c956eb44db" + }, + "bitops": { + "Package": "bitops", + "Version": "1.0-9", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "d972ef991d58c19e6efa71b21f5e144b" + }, + "bslib": { + "Package": "bslib", + "Version": "0.8.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "base64enc", + "cachem", + "fastmap", + "grDevices", + "htmltools", + "jquerylib", + "jsonlite", + "lifecycle", + "memoise", + "mime", + "rlang", + "sass" + ], + "Hash": "b299c6741ca9746fb227debcb0f9fb6c" + }, + "cachem": { + "Package": "cachem", + "Version": "1.1.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "fastmap", + "rlang" + ], + "Hash": "cd9a672193789068eb5a2aad65a0dedf" + }, + "cli": { + "Package": "cli", + "Version": "3.6.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "b21916dd77a27642b447374a5d30ecf3" + }, + "colorspace": { + "Package": "colorspace", + "Version": "2.1-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "methods", + "stats" + ], + "Hash": "d954cb1c57e8d8b756165d7ba18aa55a" + }, + "commonmark": { + "Package": "commonmark", + "Version": "1.9.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "14eb0596f987c71535d07c3aff814742" + }, + "curl": { + "Package": "curl", + "Version": "5.2.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "d91263322a58af798f6cf3b13fd56dde" + }, + "digest": { + "Package": "digest", + "Version": "0.6.37", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "33698c4b3127fc9f506654607fb73676" + }, + "dplyr": { + "Package": "dplyr", + "Version": "1.1.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "cli", + "generics", + "glue", + "lifecycle", + "magrittr", + "methods", + "pillar", + "rlang", + "tibble", + "tidyselect", + "utils", + "vctrs" + ], + "Hash": "fedd9d00c2944ff00a0e2696ccf048ec" + }, + "evaluate": { + "Package": "evaluate", + "Version": "1.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "3fd29944b231036ad67c3edb32e02201" + }, + "fansi": { + "Package": "fansi", + "Version": "1.0.6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "utils" + ], + "Hash": "962174cf2aeb5b9eea581522286a911f" + }, + "farver": { + "Package": "farver", + "Version": "2.1.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "680887028577f3fa2a81e410ed0d6e42" + }, + "fastmap": { + "Package": "fastmap", + "Version": "1.2.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "aa5e1cd11c2d15497494c5292d7ffcc8" + }, + "fontawesome": { + "Package": "fontawesome", + "Version": "0.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "htmltools", + "rlang" + ], + "Hash": "c2efdd5f0bcd1ea861c2d4e2a883a67d" + }, + "fs": { + "Package": "fs", + "Version": "1.6.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "7f48af39fa27711ea5fbd183b399920d" + }, + "generics": { + "Package": "generics", + "Version": "0.1.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "15e9634c0fcd294799e9b2e929ed1b86" + }, + "ggplot2": { + "Package": "ggplot2", + "Version": "3.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "MASS", + "R", + "cli", + "glue", + "grDevices", + "grid", + "gtable", + "isoband", + "lifecycle", + "mgcv", + "rlang", + "scales", + "stats", + "tibble", + "vctrs", + "withr" + ], + "Hash": "44c6a2f8202d5b7e878ea274b1092426" + }, + "glue": { + "Package": "glue", + "Version": "1.8.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "5899f1eaa825580172bb56c08266f37c" + }, + "gt": { + "Package": "gt", + "Version": "0.11.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "base64enc", + "bigD", + "bitops", + "cli", + "commonmark", + "dplyr", + "fs", + "glue", + "htmltools", + "htmlwidgets", + "juicyjuice", + "magrittr", + "markdown", + "reactable", + "rlang", + "sass", + "scales", + "tidyselect", + "vctrs", + "xml2" + ], + "Hash": "3170d1f0f45e531c241179ab57cd30bd" + }, + "gtable": { + "Package": "gtable", + "Version": "0.3.6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "grid", + "lifecycle", + "rlang", + "stats" + ], + "Hash": "de949855009e2d4d0e52a844e30617ae" + }, + "highr": { + "Package": "highr", + "Version": "0.11", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "xfun" + ], + "Hash": "d65ba49117ca223614f71b60d85b8ab7" + }, + "htmltools": { + "Package": "htmltools", + "Version": "0.5.8.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "base64enc", + "digest", + "fastmap", + "grDevices", + "rlang", + "utils" + ], + "Hash": "81d371a9cc60640e74e4ab6ac46dcedc" + }, + "htmlwidgets": { + "Package": "htmlwidgets", + "Version": "1.6.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grDevices", + "htmltools", + "jsonlite", + "knitr", + "rmarkdown", + "yaml" + ], + "Hash": "04291cc45198225444a397606810ac37" + }, + "isoband": { + "Package": "isoband", + "Version": "0.2.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grid", + "utils" + ], + "Hash": "0080607b4a1a7b28979aecef976d8bc2" + }, + "jquerylib": { + "Package": "jquerylib", + "Version": "0.1.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "htmltools" + ], + "Hash": "5aab57a3bd297eee1c1d862735972182" + }, + "jsonlite": { + "Package": "jsonlite", + "Version": "1.8.9", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "methods" + ], + "Hash": "4e993b65c2c3ffbffce7bb3e2c6f832b" + }, + "juicyjuice": { + "Package": "juicyjuice", + "Version": "0.1.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "V8" + ], + "Hash": "3bcd11943da509341838da9399e18bce" + }, + "knitr": { + "Package": "knitr", + "Version": "1.49", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "evaluate", + "highr", + "methods", + "tools", + "xfun", + "yaml" + ], + "Hash": "9fcb189926d93c636dea94fbe4f44480" + }, + "labeling": { + "Package": "labeling", + "Version": "0.4.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "graphics", + "stats" + ], + "Hash": "b64ec208ac5bc1852b285f665d6368b3" + }, + "lattice": { + "Package": "lattice", + "Version": "0.22-6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "grid", + "stats", + "utils" + ], + "Hash": "cc5ac1ba4c238c7ca9fa6a87ca11a7e2" + }, + "lifecycle": { + "Package": "lifecycle", + "Version": "1.0.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "rlang" + ], + "Hash": "b8552d117e1b808b09a832f589b79035" + }, + "magrittr": { + "Package": "magrittr", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "7ce2733a9826b3aeb1775d56fd305472" + }, + "markdown": { + "Package": "markdown", + "Version": "1.13", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "commonmark", + "utils", + "xfun" + ], + "Hash": "074efab766a9d6360865ad39512f2a7e" + }, + "memoise": { + "Package": "memoise", + "Version": "2.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "cachem", + "rlang" + ], + "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c" + }, + "mgcv": { + "Package": "mgcv", + "Version": "1.9-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Matrix", + "R", + "graphics", + "methods", + "nlme", + "splines", + "stats", + "utils" + ], + "Hash": "110ee9d83b496279960e162ac97764ce" + }, + "mime": { + "Package": "mime", + "Version": "0.12", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "tools" + ], + "Hash": "18e9c28c1d3ca1560ce30658b22ce104" + }, + "munsell": { + "Package": "munsell", + "Version": "0.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "colorspace", + "methods" + ], + "Hash": "4fd8900853b746af55b81fda99da7695" + }, + "nlme": { + "Package": "nlme", + "Version": "3.1-166", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "graphics", + "lattice", + "stats", + "utils" + ], + "Hash": "ccbb8846be320b627e6aa2b4616a2ded" + }, + "pillar": { + "Package": "pillar", + "Version": "1.9.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "cli", + "fansi", + "glue", + "lifecycle", + "rlang", + "utf8", + "utils", + "vctrs" + ], + "Hash": "15da5a8412f317beeee6175fbc76f4bb" + }, + "pkgconfig": { + "Package": "pkgconfig", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "utils" + ], + "Hash": "01f28d4278f15c76cddbea05899c5d6f" + }, + "rappdirs": { + "Package": "rappdirs", + "Version": "0.3.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "5e3c5dc0b071b21fa128676560dbe94d" + }, + "reactR": { + "Package": "reactR", + "Version": "0.6.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "htmltools" + ], + "Hash": "b8e3d93f508045812f47136c7c44c251" + }, + "reactable": { + "Package": "reactable", + "Version": "0.4.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "digest", + "htmltools", + "htmlwidgets", + "jsonlite", + "reactR" + ], + "Hash": "6069eb2a6597963eae0605c1875ff14c" + }, + "renv": { + "Package": "renv", + "Version": "1.0.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "utils" + ], + "Hash": "397b7b2a265bc5a7a06852524dabae20" + }, + "rlang": { + "Package": "rlang", + "Version": "1.1.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "3eec01f8b1dee337674b2e34ab1f9bc1" + }, + "rmarkdown": { + "Package": "rmarkdown", + "Version": "2.29", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "bslib", + "evaluate", + "fontawesome", + "htmltools", + "jquerylib", + "jsonlite", + "knitr", + "methods", + "tinytex", + "tools", + "utils", + "xfun", + "yaml" + ], + "Hash": "df99277f63d01c34e95e3d2f06a79736" + }, + "sass": { + "Package": "sass", + "Version": "0.4.9", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R6", + "fs", + "htmltools", + "rappdirs", + "rlang" + ], + "Hash": "d53dbfddf695303ea4ad66f86e99b95d" + }, + "scales": { + "Package": "scales", + "Version": "1.3.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "RColorBrewer", + "cli", + "farver", + "glue", + "labeling", + "lifecycle", + "munsell", + "rlang", + "viridisLite" + ], + "Hash": "c19df082ba346b0ffa6f833e92de34d1" + }, + "showtext": { + "Package": "showtext", + "Version": "0.9-7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grDevices", + "showtextdb", + "sysfonts" + ], + "Hash": "ebc23fc796c28737ffe0a64e5404f3d1" + }, + "showtextdb": { + "Package": "showtextdb", + "Version": "3.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "sysfonts", + "utils" + ], + "Hash": "c12e756cf947e58b0f2c2a520521a5a8" + }, + "stringi": { + "Package": "stringi", + "Version": "1.8.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "stats", + "tools", + "utils" + ], + "Hash": "39e1144fd75428983dc3f63aa53dfa91" + }, + "stringr": { + "Package": "stringr", + "Version": "1.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "lifecycle", + "magrittr", + "rlang", + "stringi", + "vctrs" + ], + "Hash": "960e2ae9e09656611e0b8214ad543207" + }, + "sysfonts": { + "Package": "sysfonts", + "Version": "0.8.9", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "7dfca1e9c5c278300b5ca6a1772072f7" + }, + "tibble": { + "Package": "tibble", + "Version": "3.2.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "fansi", + "lifecycle", + "magrittr", + "methods", + "pillar", + "pkgconfig", + "rlang", + "utils", + "vctrs" + ], + "Hash": "a84e2cc86d07289b3b6f5069df7a004c" + }, + "tidyselect": { + "Package": "tidyselect", + "Version": "1.2.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "lifecycle", + "rlang", + "vctrs", + "withr" + ], + "Hash": "829f27b9c4919c16b593794a6344d6c0" + }, + "tinytex": { + "Package": "tinytex", + "Version": "0.54", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "xfun" + ], + "Hash": "3ec7e3ddcacc2d34a9046941222bf94d" + }, + "utf8": { + "Package": "utf8", + "Version": "1.2.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "62b65c52671e6665f803ff02954446e9" + }, + "vctrs": { + "Package": "vctrs", + "Version": "0.6.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "lifecycle", + "rlang" + ], + "Hash": "c03fa420630029418f7e6da3667aac4a" + }, + "viridisLite": { + "Package": "viridisLite", + "Version": "0.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "c826c7c4241b6fc89ff55aaea3fa7491" + }, + "withr": { + "Package": "withr", + "Version": "3.0.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics" + ], + "Hash": "cc2d62c76458d425210d1eb1478b30b4" + }, + "xfun": { + "Package": "xfun", + "Version": "0.49", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "stats", + "tools" + ], + "Hash": "8687398773806cfff9401a2feca96298" + }, + "xml2": { + "Package": "xml2", + "Version": "1.3.6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "methods", + "rlang" + ], + "Hash": "1d0336142f4cd25d8d23cd3ba7a8fb61" + }, + "yaml": { + "Package": "yaml", + "Version": "2.3.10", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "51dab85c6c98e50a18d7551e9d49f76c" + } + } +} diff --git a/renv/.gitignore b/renv/.gitignore new file mode 100644 index 0000000..0ec0cbb --- /dev/null +++ b/renv/.gitignore @@ -0,0 +1,7 @@ +library/ +local/ +cellar/ +lock/ +python/ +sandbox/ +staging/ diff --git a/renv/activate.R b/renv/activate.R new file mode 100644 index 0000000..d13f993 --- /dev/null +++ b/renv/activate.R @@ -0,0 +1,1220 @@ + +local({ + + # the requested version of renv + version <- "1.0.7" + attr(version, "sha") <- NULL + + # the project directory + project <- Sys.getenv("RENV_PROJECT") + if (!nzchar(project)) + project <- getwd() + + # use start-up diagnostics if enabled + diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE") + if (diagnostics) { + start <- Sys.time() + profile <- tempfile("renv-startup-", fileext = ".Rprof") + utils::Rprof(profile) + on.exit({ + utils::Rprof(NULL) + elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L) + writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed))) + writeLines(sprintf("- Profile: %s", profile)) + print(utils::summaryRprof(profile)) + }, add = TRUE) + } + + # figure out whether the autoloader is enabled + enabled <- local({ + + # first, check config option + override <- getOption("renv.config.autoloader.enabled") + if (!is.null(override)) + return(override) + + # if we're being run in a context where R_LIBS is already set, + # don't load -- presumably we're being run as a sub-process and + # the parent process has already set up library paths for us + rcmd <- Sys.getenv("R_CMD", unset = NA) + rlibs <- Sys.getenv("R_LIBS", unset = NA) + if (!is.na(rlibs) && !is.na(rcmd)) + return(FALSE) + + # next, check environment variables + # TODO: prefer using the configuration one in the future + envvars <- c( + "RENV_CONFIG_AUTOLOADER_ENABLED", + "RENV_AUTOLOADER_ENABLED", + "RENV_ACTIVATE_PROJECT" + ) + + for (envvar in envvars) { + envval <- Sys.getenv(envvar, unset = NA) + if (!is.na(envval)) + return(tolower(envval) %in% c("true", "t", "1")) + } + + # enable by default + TRUE + + }) + + # bail if we're not enabled + if (!enabled) { + + # if we're not enabled, we might still need to manually load + # the user profile here + profile <- Sys.getenv("R_PROFILE_USER", unset = "~/.Rprofile") + if (file.exists(profile)) { + cfg <- Sys.getenv("RENV_CONFIG_USER_PROFILE", unset = "TRUE") + if (tolower(cfg) %in% c("true", "t", "1")) + sys.source(profile, envir = globalenv()) + } + + return(FALSE) + + } + + # avoid recursion + if (identical(getOption("renv.autoloader.running"), TRUE)) { + warning("ignoring recursive attempt to run renv autoloader") + return(invisible(TRUE)) + } + + # signal that we're loading renv during R startup + options(renv.autoloader.running = TRUE) + on.exit(options(renv.autoloader.running = NULL), add = TRUE) + + # signal that we've consented to use renv + options(renv.consent = TRUE) + + # load the 'utils' package eagerly -- this ensures that renv shims, which + # mask 'utils' packages, will come first on the search path + library(utils, lib.loc = .Library) + + # unload renv if it's already been loaded + if ("renv" %in% loadedNamespaces()) + unloadNamespace("renv") + + # load bootstrap tools + `%||%` <- function(x, y) { + if (is.null(x)) y else x + } + + catf <- function(fmt, ..., appendLF = TRUE) { + + quiet <- getOption("renv.bootstrap.quiet", default = FALSE) + if (quiet) + return(invisible()) + + msg <- sprintf(fmt, ...) + cat(msg, file = stdout(), sep = if (appendLF) "\n" else "") + + invisible(msg) + + } + + header <- function(label, + ..., + prefix = "#", + suffix = "-", + n = min(getOption("width"), 78)) + { + label <- sprintf(label, ...) + n <- max(n - nchar(label) - nchar(prefix) - 2L, 8L) + if (n <= 0) + return(paste(prefix, label)) + + tail <- paste(rep.int(suffix, n), collapse = "") + paste0(prefix, " ", label, " ", tail) + + } + + heredoc <- function(text, leave = 0) { + + # remove leading, trailing whitespace + trimmed <- gsub("^\\s*\\n|\\n\\s*$", "", text) + + # split into lines + lines <- strsplit(trimmed, "\n", fixed = TRUE)[[1L]] + + # compute common indent + indent <- regexpr("[^[:space:]]", lines) + common <- min(setdiff(indent, -1L)) - leave + paste(substring(lines, common), collapse = "\n") + + } + + startswith <- function(string, prefix) { + substring(string, 1, nchar(prefix)) == prefix + } + + bootstrap <- function(version, library) { + + friendly <- renv_bootstrap_version_friendly(version) + section <- header(sprintf("Bootstrapping renv %s", friendly)) + catf(section) + + # attempt to download renv + catf("- Downloading renv ... ", appendLF = FALSE) + withCallingHandlers( + tarball <- renv_bootstrap_download(version), + error = function(err) { + catf("FAILED") + stop("failed to download:\n", conditionMessage(err)) + } + ) + catf("OK") + on.exit(unlink(tarball), add = TRUE) + + # now attempt to install + catf("- Installing renv ... ", appendLF = FALSE) + withCallingHandlers( + status <- renv_bootstrap_install(version, tarball, library), + error = function(err) { + catf("FAILED") + stop("failed to install:\n", conditionMessage(err)) + } + ) + catf("OK") + + # add empty line to break up bootstrapping from normal output + catf("") + + return(invisible()) + } + + renv_bootstrap_tests_running <- function() { + getOption("renv.tests.running", default = FALSE) + } + + renv_bootstrap_repos <- function() { + + # get CRAN repository + cran <- getOption("renv.repos.cran", "https://cloud.r-project.org") + + # check for repos override + repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA) + if (!is.na(repos)) { + + # check for RSPM; if set, use a fallback repository for renv + rspm <- Sys.getenv("RSPM", unset = NA) + if (identical(rspm, repos)) + repos <- c(RSPM = rspm, CRAN = cran) + + return(repos) + + } + + # check for lockfile repositories + repos <- tryCatch(renv_bootstrap_repos_lockfile(), error = identity) + if (!inherits(repos, "error") && length(repos)) + return(repos) + + # retrieve current repos + repos <- getOption("repos") + + # ensure @CRAN@ entries are resolved + repos[repos == "@CRAN@"] <- cran + + # add in renv.bootstrap.repos if set + default <- c(FALLBACK = "https://cloud.r-project.org") + extra <- getOption("renv.bootstrap.repos", default = default) + repos <- c(repos, extra) + + # remove duplicates that might've snuck in + dupes <- duplicated(repos) | duplicated(names(repos)) + repos[!dupes] + + } + + renv_bootstrap_repos_lockfile <- function() { + + lockpath <- Sys.getenv("RENV_PATHS_LOCKFILE", unset = "renv.lock") + if (!file.exists(lockpath)) + return(NULL) + + lockfile <- tryCatch(renv_json_read(lockpath), error = identity) + if (inherits(lockfile, "error")) { + warning(lockfile) + return(NULL) + } + + repos <- lockfile$R$Repositories + if (length(repos) == 0) + return(NULL) + + keys <- vapply(repos, `[[`, "Name", FUN.VALUE = character(1)) + vals <- vapply(repos, `[[`, "URL", FUN.VALUE = character(1)) + names(vals) <- keys + + return(vals) + + } + + renv_bootstrap_download <- function(version) { + + sha <- attr(version, "sha", exact = TRUE) + + methods <- if (!is.null(sha)) { + + # attempting to bootstrap a development version of renv + c( + function() renv_bootstrap_download_tarball(sha), + function() renv_bootstrap_download_github(sha) + ) + + } else { + + # attempting to bootstrap a release version of renv + c( + function() renv_bootstrap_download_tarball(version), + function() renv_bootstrap_download_cran_latest(version), + function() renv_bootstrap_download_cran_archive(version) + ) + + } + + for (method in methods) { + path <- tryCatch(method(), error = identity) + if (is.character(path) && file.exists(path)) + return(path) + } + + stop("All download methods failed") + + } + + renv_bootstrap_download_impl <- function(url, destfile) { + + mode <- "wb" + + # https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17715 + fixup <- + Sys.info()[["sysname"]] == "Windows" && + substring(url, 1L, 5L) == "file:" + + if (fixup) + mode <- "w+b" + + args <- list( + url = url, + destfile = destfile, + mode = mode, + quiet = TRUE + ) + + if ("headers" %in% names(formals(utils::download.file))) + args$headers <- renv_bootstrap_download_custom_headers(url) + + do.call(utils::download.file, args) + + } + + renv_bootstrap_download_custom_headers <- function(url) { + + headers <- getOption("renv.download.headers") + if (is.null(headers)) + return(character()) + + if (!is.function(headers)) + stopf("'renv.download.headers' is not a function") + + headers <- headers(url) + if (length(headers) == 0L) + return(character()) + + if (is.list(headers)) + headers <- unlist(headers, recursive = FALSE, use.names = TRUE) + + ok <- + is.character(headers) && + is.character(names(headers)) && + all(nzchar(names(headers))) + + if (!ok) + stop("invocation of 'renv.download.headers' did not return a named character vector") + + headers + + } + + renv_bootstrap_download_cran_latest <- function(version) { + + spec <- renv_bootstrap_download_cran_latest_find(version) + type <- spec$type + repos <- spec$repos + + baseurl <- utils::contrib.url(repos = repos, type = type) + ext <- if (identical(type, "source")) + ".tar.gz" + else if (Sys.info()[["sysname"]] == "Windows") + ".zip" + else + ".tgz" + name <- sprintf("renv_%s%s", version, ext) + url <- paste(baseurl, name, sep = "/") + + destfile <- file.path(tempdir(), name) + status <- tryCatch( + renv_bootstrap_download_impl(url, destfile), + condition = identity + ) + + if (inherits(status, "condition")) + return(FALSE) + + # report success and return + destfile + + } + + renv_bootstrap_download_cran_latest_find <- function(version) { + + # check whether binaries are supported on this system + binary <- + getOption("renv.bootstrap.binary", default = TRUE) && + !identical(.Platform$pkgType, "source") && + !identical(getOption("pkgType"), "source") && + Sys.info()[["sysname"]] %in% c("Darwin", "Windows") + + types <- c(if (binary) "binary", "source") + + # iterate over types + repositories + for (type in types) { + for (repos in renv_bootstrap_repos()) { + + # retrieve package database + db <- tryCatch( + as.data.frame( + utils::available.packages(type = type, repos = repos), + stringsAsFactors = FALSE + ), + error = identity + ) + + if (inherits(db, "error")) + next + + # check for compatible entry + entry <- db[db$Package %in% "renv" & db$Version %in% version, ] + if (nrow(entry) == 0) + next + + # found it; return spec to caller + spec <- list(entry = entry, type = type, repos = repos) + return(spec) + + } + } + + # if we got here, we failed to find renv + fmt <- "renv %s is not available from your declared package repositories" + stop(sprintf(fmt, version)) + + } + + renv_bootstrap_download_cran_archive <- function(version) { + + name <- sprintf("renv_%s.tar.gz", version) + repos <- renv_bootstrap_repos() + urls <- file.path(repos, "src/contrib/Archive/renv", name) + destfile <- file.path(tempdir(), name) + + for (url in urls) { + + status <- tryCatch( + renv_bootstrap_download_impl(url, destfile), + condition = identity + ) + + if (identical(status, 0L)) + return(destfile) + + } + + return(FALSE) + + } + + renv_bootstrap_download_tarball <- function(version) { + + # if the user has provided the path to a tarball via + # an environment variable, then use it + tarball <- Sys.getenv("RENV_BOOTSTRAP_TARBALL", unset = NA) + if (is.na(tarball)) + return() + + # allow directories + if (dir.exists(tarball)) { + name <- sprintf("renv_%s.tar.gz", version) + tarball <- file.path(tarball, name) + } + + # bail if it doesn't exist + if (!file.exists(tarball)) { + + # let the user know we weren't able to honour their request + fmt <- "- RENV_BOOTSTRAP_TARBALL is set (%s) but does not exist." + msg <- sprintf(fmt, tarball) + warning(msg) + + # bail + return() + + } + + catf("- Using local tarball '%s'.", tarball) + tarball + + } + + renv_bootstrap_download_github <- function(version) { + + enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE") + if (!identical(enabled, "TRUE")) + return(FALSE) + + # prepare download options + pat <- Sys.getenv("GITHUB_PAT") + if (nzchar(Sys.which("curl")) && nzchar(pat)) { + fmt <- "--location --fail --header \"Authorization: token %s\"" + extra <- sprintf(fmt, pat) + saved <- options("download.file.method", "download.file.extra") + options(download.file.method = "curl", download.file.extra = extra) + on.exit(do.call(base::options, saved), add = TRUE) + } else if (nzchar(Sys.which("wget")) && nzchar(pat)) { + fmt <- "--header=\"Authorization: token %s\"" + extra <- sprintf(fmt, pat) + saved <- options("download.file.method", "download.file.extra") + options(download.file.method = "wget", download.file.extra = extra) + on.exit(do.call(base::options, saved), add = TRUE) + } + + url <- file.path("https://api.github.com/repos/rstudio/renv/tarball", version) + name <- sprintf("renv_%s.tar.gz", version) + destfile <- file.path(tempdir(), name) + + status <- tryCatch( + renv_bootstrap_download_impl(url, destfile), + condition = identity + ) + + if (!identical(status, 0L)) + return(FALSE) + + renv_bootstrap_download_augment(destfile) + + return(destfile) + + } + + # Add Sha to DESCRIPTION. This is stop gap until #890, after which we + # can use renv::install() to fully capture metadata. + renv_bootstrap_download_augment <- function(destfile) { + sha <- renv_bootstrap_git_extract_sha1_tar(destfile) + if (is.null(sha)) { + return() + } + + # Untar + tempdir <- tempfile("renv-github-") + on.exit(unlink(tempdir, recursive = TRUE), add = TRUE) + untar(destfile, exdir = tempdir) + pkgdir <- dir(tempdir, full.names = TRUE)[[1]] + + # Modify description + desc_path <- file.path(pkgdir, "DESCRIPTION") + desc_lines <- readLines(desc_path) + remotes_fields <- c( + "RemoteType: github", + "RemoteHost: api.github.com", + "RemoteRepo: renv", + "RemoteUsername: rstudio", + "RemotePkgRef: rstudio/renv", + paste("RemoteRef: ", sha), + paste("RemoteSha: ", sha) + ) + writeLines(c(desc_lines[desc_lines != ""], remotes_fields), con = desc_path) + + # Re-tar + local({ + old <- setwd(tempdir) + on.exit(setwd(old), add = TRUE) + + tar(destfile, compression = "gzip") + }) + invisible() + } + + # Extract the commit hash from a git archive. Git archives include the SHA1 + # hash as the comment field of the tarball pax extended header + # (see https://www.kernel.org/pub/software/scm/git/docs/git-archive.html) + # For GitHub archives this should be the first header after the default one + # (512 byte) header. + renv_bootstrap_git_extract_sha1_tar <- function(bundle) { + + # open the bundle for reading + # We use gzcon for everything because (from ?gzcon) + # > Reading from a connection which does not supply a 'gzip' magic + # > header is equivalent to reading from the original connection + conn <- gzcon(file(bundle, open = "rb", raw = TRUE)) + on.exit(close(conn)) + + # The default pax header is 512 bytes long and the first pax extended header + # with the comment should be 51 bytes long + # `52 comment=` (11 chars) + 40 byte SHA1 hash + len <- 0x200 + 0x33 + res <- rawToChar(readBin(conn, "raw", n = len)[0x201:len]) + + if (grepl("^52 comment=", res)) { + sub("52 comment=", "", res) + } else { + NULL + } + } + + renv_bootstrap_install <- function(version, tarball, library) { + + # attempt to install it into project library + dir.create(library, showWarnings = FALSE, recursive = TRUE) + output <- renv_bootstrap_install_impl(library, tarball) + + # check for successful install + status <- attr(output, "status") + if (is.null(status) || identical(status, 0L)) + return(status) + + # an error occurred; report it + header <- "installation of renv failed" + lines <- paste(rep.int("=", nchar(header)), collapse = "") + text <- paste(c(header, lines, output), collapse = "\n") + stop(text) + + } + + renv_bootstrap_install_impl <- function(library, tarball) { + + # invoke using system2 so we can capture and report output + bin <- R.home("bin") + exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" + R <- file.path(bin, exe) + + args <- c( + "--vanilla", "CMD", "INSTALL", "--no-multiarch", + "-l", shQuote(path.expand(library)), + shQuote(path.expand(tarball)) + ) + + system2(R, args, stdout = TRUE, stderr = TRUE) + + } + + renv_bootstrap_platform_prefix <- function() { + + # construct version prefix + version <- paste(R.version$major, R.version$minor, sep = ".") + prefix <- paste("R", numeric_version(version)[1, 1:2], sep = "-") + + # include SVN revision for development versions of R + # (to avoid sharing platform-specific artefacts with released versions of R) + devel <- + identical(R.version[["status"]], "Under development (unstable)") || + identical(R.version[["nickname"]], "Unsuffered Consequences") + + if (devel) + prefix <- paste(prefix, R.version[["svn rev"]], sep = "-r") + + # build list of path components + components <- c(prefix, R.version$platform) + + # include prefix if provided by user + prefix <- renv_bootstrap_platform_prefix_impl() + if (!is.na(prefix) && nzchar(prefix)) + components <- c(prefix, components) + + # build prefix + paste(components, collapse = "/") + + } + + renv_bootstrap_platform_prefix_impl <- function() { + + # if an explicit prefix has been supplied, use it + prefix <- Sys.getenv("RENV_PATHS_PREFIX", unset = NA) + if (!is.na(prefix)) + return(prefix) + + # if the user has requested an automatic prefix, generate it + auto <- Sys.getenv("RENV_PATHS_PREFIX_AUTO", unset = NA) + if (is.na(auto) && getRversion() >= "4.4.0") + auto <- "TRUE" + + if (auto %in% c("TRUE", "True", "true", "1")) + return(renv_bootstrap_platform_prefix_auto()) + + # empty string on failure + "" + + } + + renv_bootstrap_platform_prefix_auto <- function() { + + prefix <- tryCatch(renv_bootstrap_platform_os(), error = identity) + if (inherits(prefix, "error") || prefix %in% "unknown") { + + msg <- paste( + "failed to infer current operating system", + "please file a bug report at https://github.com/rstudio/renv/issues", + sep = "; " + ) + + warning(msg) + + } + + prefix + + } + + renv_bootstrap_platform_os <- function() { + + sysinfo <- Sys.info() + sysname <- sysinfo[["sysname"]] + + # handle Windows + macOS up front + if (sysname == "Windows") + return("windows") + else if (sysname == "Darwin") + return("macos") + + # check for os-release files + for (file in c("/etc/os-release", "/usr/lib/os-release")) + if (file.exists(file)) + return(renv_bootstrap_platform_os_via_os_release(file, sysinfo)) + + # check for redhat-release files + if (file.exists("/etc/redhat-release")) + return(renv_bootstrap_platform_os_via_redhat_release()) + + "unknown" + + } + + renv_bootstrap_platform_os_via_os_release <- function(file, sysinfo) { + + # read /etc/os-release + release <- utils::read.table( + file = file, + sep = "=", + quote = c("\"", "'"), + col.names = c("Key", "Value"), + comment.char = "#", + stringsAsFactors = FALSE + ) + + vars <- as.list(release$Value) + names(vars) <- release$Key + + # get os name + os <- tolower(sysinfo[["sysname"]]) + + # read id + id <- "unknown" + for (field in c("ID", "ID_LIKE")) { + if (field %in% names(vars) && nzchar(vars[[field]])) { + id <- vars[[field]] + break + } + } + + # read version + version <- "unknown" + for (field in c("UBUNTU_CODENAME", "VERSION_CODENAME", "VERSION_ID", "BUILD_ID")) { + if (field %in% names(vars) && nzchar(vars[[field]])) { + version <- vars[[field]] + break + } + } + + # join together + paste(c(os, id, version), collapse = "-") + + } + + renv_bootstrap_platform_os_via_redhat_release <- function() { + + # read /etc/redhat-release + contents <- readLines("/etc/redhat-release", warn = FALSE) + + # infer id + id <- if (grepl("centos", contents, ignore.case = TRUE)) + "centos" + else if (grepl("redhat", contents, ignore.case = TRUE)) + "redhat" + else + "unknown" + + # try to find a version component (very hacky) + version <- "unknown" + + parts <- strsplit(contents, "[[:space:]]")[[1L]] + for (part in parts) { + + nv <- tryCatch(numeric_version(part), error = identity) + if (inherits(nv, "error")) + next + + version <- nv[1, 1] + break + + } + + paste(c("linux", id, version), collapse = "-") + + } + + renv_bootstrap_library_root_name <- function(project) { + + # use project name as-is if requested + asis <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT_ASIS", unset = "FALSE") + if (asis) + return(basename(project)) + + # otherwise, disambiguate based on project's path + id <- substring(renv_bootstrap_hash_text(project), 1L, 8L) + paste(basename(project), id, sep = "-") + + } + + renv_bootstrap_library_root <- function(project) { + + prefix <- renv_bootstrap_profile_prefix() + + path <- Sys.getenv("RENV_PATHS_LIBRARY", unset = NA) + if (!is.na(path)) + return(paste(c(path, prefix), collapse = "/")) + + path <- renv_bootstrap_library_root_impl(project) + if (!is.null(path)) { + name <- renv_bootstrap_library_root_name(project) + return(paste(c(path, prefix, name), collapse = "/")) + } + + renv_bootstrap_paths_renv("library", project = project) + + } + + renv_bootstrap_library_root_impl <- function(project) { + + root <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT", unset = NA) + if (!is.na(root)) + return(root) + + type <- renv_bootstrap_project_type(project) + if (identical(type, "package")) { + userdir <- renv_bootstrap_user_dir() + return(file.path(userdir, "library")) + } + + } + + renv_bootstrap_validate_version <- function(version, description = NULL) { + + # resolve description file + # + # avoid passing lib.loc to `packageDescription()` below, since R will + # use the loaded version of the package by default anyhow. note that + # this function should only be called after 'renv' is loaded + # https://github.com/rstudio/renv/issues/1625 + description <- description %||% packageDescription("renv") + + # check whether requested version 'version' matches loaded version of renv + sha <- attr(version, "sha", exact = TRUE) + valid <- if (!is.null(sha)) + renv_bootstrap_validate_version_dev(sha, description) + else + renv_bootstrap_validate_version_release(version, description) + + if (valid) + return(TRUE) + + # the loaded version of renv doesn't match the requested version; + # give the user instructions on how to proceed + dev <- identical(description[["RemoteType"]], "github") + remote <- if (dev) + paste("rstudio/renv", description[["RemoteSha"]], sep = "@") + else + paste("renv", description[["Version"]], sep = "@") + + # display both loaded version + sha if available + friendly <- renv_bootstrap_version_friendly( + version = description[["Version"]], + sha = if (dev) description[["RemoteSha"]] + ) + + fmt <- heredoc(" + renv %1$s was loaded from project library, but this project is configured to use renv %2$s. + - Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile. + - Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library. + ") + catf(fmt, friendly, renv_bootstrap_version_friendly(version), remote) + + FALSE + + } + + renv_bootstrap_validate_version_dev <- function(version, description) { + expected <- description[["RemoteSha"]] + is.character(expected) && startswith(expected, version) + } + + renv_bootstrap_validate_version_release <- function(version, description) { + expected <- description[["Version"]] + is.character(expected) && identical(expected, version) + } + + renv_bootstrap_hash_text <- function(text) { + + hashfile <- tempfile("renv-hash-") + on.exit(unlink(hashfile), add = TRUE) + + writeLines(text, con = hashfile) + tools::md5sum(hashfile) + + } + + renv_bootstrap_load <- function(project, libpath, version) { + + # try to load renv from the project library + if (!requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) + return(FALSE) + + # warn if the version of renv loaded does not match + renv_bootstrap_validate_version(version) + + # execute renv load hooks, if any + hooks <- getHook("renv::autoload") + for (hook in hooks) + if (is.function(hook)) + tryCatch(hook(), error = warnify) + + # load the project + renv::load(project) + + TRUE + + } + + renv_bootstrap_profile_load <- function(project) { + + # if RENV_PROFILE is already set, just use that + profile <- Sys.getenv("RENV_PROFILE", unset = NA) + if (!is.na(profile) && nzchar(profile)) + return(profile) + + # check for a profile file (nothing to do if it doesn't exist) + path <- renv_bootstrap_paths_renv("profile", profile = FALSE, project = project) + if (!file.exists(path)) + return(NULL) + + # read the profile, and set it if it exists + contents <- readLines(path, warn = FALSE) + if (length(contents) == 0L) + return(NULL) + + # set RENV_PROFILE + profile <- contents[[1L]] + if (!profile %in% c("", "default")) + Sys.setenv(RENV_PROFILE = profile) + + profile + + } + + renv_bootstrap_profile_prefix <- function() { + profile <- renv_bootstrap_profile_get() + if (!is.null(profile)) + return(file.path("profiles", profile, "renv")) + } + + renv_bootstrap_profile_get <- function() { + profile <- Sys.getenv("RENV_PROFILE", unset = "") + renv_bootstrap_profile_normalize(profile) + } + + renv_bootstrap_profile_set <- function(profile) { + profile <- renv_bootstrap_profile_normalize(profile) + if (is.null(profile)) + Sys.unsetenv("RENV_PROFILE") + else + Sys.setenv(RENV_PROFILE = profile) + } + + renv_bootstrap_profile_normalize <- function(profile) { + + if (is.null(profile) || profile %in% c("", "default")) + return(NULL) + + profile + + } + + renv_bootstrap_path_absolute <- function(path) { + + substr(path, 1L, 1L) %in% c("~", "/", "\\") || ( + substr(path, 1L, 1L) %in% c(letters, LETTERS) && + substr(path, 2L, 3L) %in% c(":/", ":\\") + ) + + } + + renv_bootstrap_paths_renv <- function(..., profile = TRUE, project = NULL) { + renv <- Sys.getenv("RENV_PATHS_RENV", unset = "renv") + root <- if (renv_bootstrap_path_absolute(renv)) NULL else project + prefix <- if (profile) renv_bootstrap_profile_prefix() + components <- c(root, renv, prefix, ...) + paste(components, collapse = "/") + } + + renv_bootstrap_project_type <- function(path) { + + descpath <- file.path(path, "DESCRIPTION") + if (!file.exists(descpath)) + return("unknown") + + desc <- tryCatch( + read.dcf(descpath, all = TRUE), + error = identity + ) + + if (inherits(desc, "error")) + return("unknown") + + type <- desc$Type + if (!is.null(type)) + return(tolower(type)) + + package <- desc$Package + if (!is.null(package)) + return("package") + + "unknown" + + } + + renv_bootstrap_user_dir <- function() { + dir <- renv_bootstrap_user_dir_impl() + path.expand(chartr("\\", "/", dir)) + } + + renv_bootstrap_user_dir_impl <- function() { + + # use local override if set + override <- getOption("renv.userdir.override") + if (!is.null(override)) + return(override) + + # use R_user_dir if available + tools <- asNamespace("tools") + if (is.function(tools$R_user_dir)) + return(tools$R_user_dir("renv", "cache")) + + # try using our own backfill for older versions of R + envvars <- c("R_USER_CACHE_DIR", "XDG_CACHE_HOME") + for (envvar in envvars) { + root <- Sys.getenv(envvar, unset = NA) + if (!is.na(root)) + return(file.path(root, "R/renv")) + } + + # use platform-specific default fallbacks + if (Sys.info()[["sysname"]] == "Windows") + file.path(Sys.getenv("LOCALAPPDATA"), "R/cache/R/renv") + else if (Sys.info()[["sysname"]] == "Darwin") + "~/Library/Caches/org.R-project.R/R/renv" + else + "~/.cache/R/renv" + + } + + renv_bootstrap_version_friendly <- function(version, shafmt = NULL, sha = NULL) { + sha <- sha %||% attr(version, "sha", exact = TRUE) + parts <- c(version, sprintf(shafmt %||% " [sha: %s]", substring(sha, 1L, 7L))) + paste(parts, collapse = "") + } + + renv_bootstrap_exec <- function(project, libpath, version) { + if (!renv_bootstrap_load(project, libpath, version)) + renv_bootstrap_run(version, libpath) + } + + renv_bootstrap_run <- function(version, libpath) { + + # perform bootstrap + bootstrap(version, libpath) + + # exit early if we're just testing bootstrap + if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) + return(TRUE) + + # try again to load + if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { + return(renv::load(project = getwd())) + } + + # failed to download or load renv; warn the user + msg <- c( + "Failed to find an renv installation: the project will not be loaded.", + "Use `renv::activate()` to re-initialize the project." + ) + + warning(paste(msg, collapse = "\n"), call. = FALSE) + + } + + renv_json_read <- function(file = NULL, text = NULL) { + + jlerr <- NULL + + # if jsonlite is loaded, use that instead + if ("jsonlite" %in% loadedNamespaces()) { + + json <- tryCatch(renv_json_read_jsonlite(file, text), error = identity) + if (!inherits(json, "error")) + return(json) + + jlerr <- json + + } + + # otherwise, fall back to the default JSON reader + json <- tryCatch(renv_json_read_default(file, text), error = identity) + if (!inherits(json, "error")) + return(json) + + # report an error + if (!is.null(jlerr)) + stop(jlerr) + else + stop(json) + + } + + renv_json_read_jsonlite <- function(file = NULL, text = NULL) { + text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n") + jsonlite::fromJSON(txt = text, simplifyVector = FALSE) + } + + renv_json_read_default <- function(file = NULL, text = NULL) { + + # find strings in the JSON + text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n") + pattern <- '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + locs <- gregexpr(pattern, text, perl = TRUE)[[1]] + + # if any are found, replace them with placeholders + replaced <- text + strings <- character() + replacements <- character() + + if (!identical(c(locs), -1L)) { + + # get the string values + starts <- locs + ends <- locs + attr(locs, "match.length") - 1L + strings <- substring(text, starts, ends) + + # only keep those requiring escaping + strings <- grep("[[\\]{}:]", strings, perl = TRUE, value = TRUE) + + # compute replacements + replacements <- sprintf('"\032%i\032"', seq_along(strings)) + + # replace the strings + mapply(function(string, replacement) { + replaced <<- sub(string, replacement, replaced, fixed = TRUE) + }, strings, replacements) + + } + + # transform the JSON into something the R parser understands + transformed <- replaced + transformed <- gsub("{}", "`names<-`(list(), character())", transformed, fixed = TRUE) + transformed <- gsub("[[{]", "list(", transformed, perl = TRUE) + transformed <- gsub("[]}]", ")", transformed, perl = TRUE) + transformed <- gsub(":", "=", transformed, fixed = TRUE) + text <- paste(transformed, collapse = "\n") + + # parse it + json <- parse(text = text, keep.source = FALSE, srcfile = NULL)[[1L]] + + # construct map between source strings, replaced strings + map <- as.character(parse(text = strings)) + names(map) <- as.character(parse(text = replacements)) + + # convert to list + map <- as.list(map) + + # remap strings in object + remapped <- renv_json_read_remap(json, map) + + # evaluate + eval(remapped, envir = baseenv()) + + } + + renv_json_read_remap <- function(json, map) { + + # fix names + if (!is.null(names(json))) { + lhs <- match(names(json), names(map), nomatch = 0L) + rhs <- match(names(map), names(json), nomatch = 0L) + names(json)[rhs] <- map[lhs] + } + + # fix values + if (is.character(json)) + return(map[[json]] %||% json) + + # handle true, false, null + if (is.name(json)) { + text <- as.character(json) + if (text == "true") + return(TRUE) + else if (text == "false") + return(FALSE) + else if (text == "null") + return(NULL) + } + + # recurse + if (is.recursive(json)) { + for (i in seq_along(json)) { + json[i] <- list(renv_json_read_remap(json[[i]], map)) + } + } + + json + + } + + # load the renv profile, if any + renv_bootstrap_profile_load(project) + + # construct path to library root + root <- renv_bootstrap_library_root(project) + + # construct library prefix for platform + prefix <- renv_bootstrap_platform_prefix() + + # construct full libpath + libpath <- file.path(root, prefix) + + # run bootstrap code + renv_bootstrap_exec(project, libpath, version) + + invisible() + +}) diff --git a/renv/settings.json b/renv/settings.json new file mode 100644 index 0000000..74c1d4b --- /dev/null +++ b/renv/settings.json @@ -0,0 +1,19 @@ +{ + "bioconductor.version": null, + "external.libraries": [], + "ignored.packages": [], + "package.dependency.fields": [ + "Imports", + "Depends", + "LinkingTo" + ], + "ppm.enabled": null, + "ppm.ignored.urls": [], + "r.version": null, + "snapshot.type": "explicit", + "use.cache": true, + "vcs.ignore.cellar": true, + "vcs.ignore.library": true, + "vcs.ignore.local": true, + "vcs.manage.ignores": true +} From aa460e8193a3ffa12deb0d9ab648d75b3cff8fb2 Mon Sep 17 00:00:00 2001 From: Brancen Gregory Date: Tue, 12 Nov 2024 17:22:23 -0600 Subject: [PATCH 21/25] Add additional deps --- DESCRIPTION | 3 +++ renv.lock | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3316c05..28c8ee3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,11 +34,14 @@ Imports: Suggests: ggrepel, knitr, + lubridate, ojodb, rmarkdown, testthat (>= 3.0.0), tibble, vdiffr +Remotes: + openjusticeok/ojodb Config/testthat/edition: 3 URL: https://openjusticeok.github.io/ojothemes/ VignetteBuilder: knitr diff --git a/renv.lock b/renv.lock index afc5771..6444353 100644 --- a/renv.lock +++ b/renv.lock @@ -1,6 +1,6 @@ { "R": { - "Version": "4.4.1", + "Version": "4.4.2", "Repositories": [ { "Name": "CRAN", From 5bba2db7f6302018e01b5f76c44d95cfee5231c9 Mon Sep 17 00:00:00 2001 From: Brancen Gregory Date: Tue, 12 Nov 2024 17:42:29 -0600 Subject: [PATCH 22/25] Add ojodb permissions for vignette building --- .github/workflows/pkgdown.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index bfc9f4d..6dc1862 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -20,6 +20,21 @@ jobs: group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + # Configuring ojodb access for github actions + OJO_HOST: ${{ secrets.OJO_HOST }} + OJO_PORT: ${{ secrets.OJO_PORT }} + OJO_DEFAULT_USER: ${{ secrets.OJO_DEFAULT_USER }} + OJO_DEFAULT_PASS: ${{ secrets.OJO_DEFAULT_PASS }} + OJO_SSL_MODE: ${{ secrets.OJO_SSL_MODE }} + # Encoded secrets + OJO_SSL_CERT_BASE64: ${{ secrets.OJO_SSL_CERT_BASE64 }} + OJO_SSL_ROOT_CERT_BASE64: ${{ secrets.OJO_SSL_ROOT_CERT_BASE64 }} + OJO_SSL_KEY_BASE64: ${{ secrets.OJO_SSL_KEY_BASE64 }} + # + OJO_SSL_CERT: ${{ github.workspace }}/certs/client-cert.pem + OJO_SSL_ROOT_CERT: ${{ github.workspace }}/certs/server-ca.pem + OJO_SSL_KEY: ${{ github.workspace }}/certs/client-key.pk8 permissions: contents: write steps: From d4a60b71836cc168117ec394372db0628923cc85 Mon Sep 17 00:00:00 2001 From: Brancen Gregory Date: Tue, 12 Nov 2024 18:05:15 -0600 Subject: [PATCH 23/25] Add secret decoding step --- .github/workflows/pkgdown.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 6dc1862..742c33c 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -51,6 +51,15 @@ jobs: extra-packages: any::pkgdown, local::. needs: website + - name: Decode secrets + shell: bash + run: | + mkdir certs + echo "$OJO_SSL_CERT_BASE64" | base64 --decode > certs/client-cert.pem + echo "$OJO_SSL_ROOT_CERT_BASE64" | base64 --decode > certs/server-ca.pem + echo "$OJO_SSL_KEY_BASE64" | base64 --decode > certs/client-key.pk8 + chmod 0600 certs/client-key.pk8 + - name: Build site run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) shell: Rscript {0} From 1cc3b1369334f402bde9e5db58902812942babbe Mon Sep 17 00:00:00 2001 From: AnthonyOKC Date: Wed, 4 Dec 2024 00:21:54 -0600 Subject: [PATCH 24/25] Modified spacing and gridlines --- R/theme_ojo.R | 8 ++--- R/theme_okpi.R | 13 ++++--- R/theme_tok.R | 11 ++++-- vignettes/ojothemes-vignette.Rmd | 61 +++++++++++++++++++------------- 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/R/theme_ojo.R b/R/theme_ojo.R index 94d146f..ee2bb88 100644 --- a/R/theme_ojo.R +++ b/R/theme_ojo.R @@ -53,7 +53,7 @@ theme_ojo_base <- function(base_size = 16, plot.caption = ggplot2::element_text(size = base_size * 9 / 8.5, hjust = 1L, vjust = 1L, - margin = ggplot2::margin(t = half_line * 0.9)), + margin = ggplot2::margin(t = base_size)), plot.caption.position = "plot", plot.background = NULL, @@ -78,7 +78,7 @@ theme_ojo_base <- function(base_size = 16, size = base_size), axis.title.x = ggplot2::element_text(margin = ggplot2::margin(t = 8L)), axis.title.y = ggplot2::element_text(angle = 90L, - margin = ggplot2::margin(r = 4L)), + margin = ggplot2::margin(r = 12L)), axis.title.x.top = NULL, axis.title.y.right = NULL, @@ -135,12 +135,12 @@ theme_ojo_base <- function(base_size = 16, panel.grid = NULL, panel.grid.major = ggplot2::element_line(), panel.grid.major.x = ggplot2::element_blank(), - panel.grid.major.y = ggplot2::element_line(colour = "#dedddd"), + panel.grid.major.y = ggplot2::element_line(colour = "#cccccc"), panel.grid.minor = ggplot2::element_line(), panel.grid.minor.x = ggplot2::element_blank(), panel.grid.minor.y = ggplot2::element_blank(), # strip attributes (Faceting) - strip.background = ggplot2::element_rect(fill = "#dedddd", + strip.background = ggplot2::element_rect(fill = "#cccccc", colour = NA, linewidth = 10L), strip.text = ggplot2::element_text(face = "bold", diff --git a/R/theme_okpi.R b/R/theme_okpi.R index 2c05b7c..9ced00c 100644 --- a/R/theme_okpi.R +++ b/R/theme_okpi.R @@ -39,8 +39,8 @@ theme_okpi_base <- function(base_size = 16, panel.border = ggplot2::element_blank(), panel.grid.major.x = ggplot2::element_blank(), panel.grid.minor.x = ggplot2::element_blank(), - panel.grid.major.y = ggplot2::element_line(linewidth = 0.5), - panel.grid.minor.y = ggplot2::element_line(linewidth = 0.25), + panel.grid.major.y = ggplot2::element_line(linewidth = 0.5, color = "#cccccc"), + panel.grid.minor.y = ggplot2::element_blank(), panel.spacing = grid::unit(6, "pt"), plot.title = ggplot2::element_text( size = ggplot2::rel(2), @@ -57,14 +57,15 @@ theme_okpi_base <- function(base_size = 16, hjust = 0, family = "Roboto Condensed", lineheight = 0.7, - margin = ggplot2::margin(0, 0, 6, 0, "pt") + margin = ggplot2::margin(0, 0, 18, 0, "pt") ), plot.caption.position = "plot", plot.caption = ggplot2::element_text( size = ggplot2::rel(1.2), lineheight = 0.75, face = "italic", - hjust = 1 + hjust = 1, + margin = ggplot2::margin(18, 0, 0, 0, "pt") ), legend.title = ggplot2::element_blank(), legend.text = ggplot2::element_text(size = ggplot2::rel(1.16)), @@ -74,6 +75,10 @@ theme_okpi_base <- function(base_size = 16, face = "bold", hjust = 0.5, ), + axis.title.y = ggplot2::element_text( + angle = 90, + margin = ggplot2::margin(0, 12, 0, 0, "pt") + ), axis.text = ggplot2::element_text( size = ggplot2::rel(1.16), hjust = 0.5 diff --git a/R/theme_tok.R b/R/theme_tok.R index 0ba2f7f..3f20af3 100644 --- a/R/theme_tok.R +++ b/R/theme_tok.R @@ -39,7 +39,7 @@ theme_tok_base <- function(base_size = 16, panel.border = ggplot2::element_blank(), panel.grid.major.x = ggplot2::element_blank(), panel.grid.minor.x = ggplot2::element_blank(), - panel.grid.major.y = ggplot2::element_line(linewidth = 0.5), + panel.grid.major.y = ggplot2::element_line(linewidth = 0.5, color = "#cccccc"), panel.grid.minor.y = ggplot2::element_blank(), panel.spacing = grid::unit(6, "pt"), plot.title = ggplot2::element_text( @@ -58,14 +58,15 @@ theme_tok_base <- function(base_size = 16, color = ojothemes::palette_tok_main[3], family = "Roboto Condensed", lineheight = 0.7, - margin = ggplot2::margin(0, 0, 6, 0, "pt") + margin = ggplot2::margin(0, 0, 18, 0, "pt") ), plot.caption.position = "plot", plot.caption = ggplot2::element_text( size = ggplot2::rel(1.2), lineheight = 0.75, face = "italic", - hjust = 1 + hjust = 1, + margin = ggplot2::margin(18, 0, 0, 0, "pt") ), legend.title = ggplot2::element_blank(), legend.text = ggplot2::element_text(size = ggplot2::rel(1.16)), @@ -75,6 +76,10 @@ theme_tok_base <- function(base_size = 16, face = "bold", hjust = 0.5, ), + axis.title.y = ggplot2::element_text( + angle = 90, + margin = ggplot2::margin(0, 12, 0, 0, "pt") + ), axis.text = ggplot2::element_text( size = ggplot2::rel(1.16), hjust = 0.5 diff --git a/vignettes/ojothemes-vignette.Rmd b/vignettes/ojothemes-vignette.Rmd index 66f66e0..ea08574 100644 --- a/vignettes/ojothemes-vignette.Rmd +++ b/vignettes/ojothemes-vignette.Rmd @@ -25,12 +25,15 @@ library(lubridate) library(gt) # Test data from OCDC -data <- ojo_tbl(schema = "ocdc", - table = "arrest") |> - filter(book_date >= "01-01-2024", - book_date < "11-01-2024") |> - ojo_collect() - +data <- ojo_tbl( + schema = "ocdc", + table = "arrest" +) |> + filter( + book_date >= "01-01-2024", + book_date < "11-01-2024" + ) |> + ojo_collect() ``` ## Themes for `ggplot` graphs @@ -40,8 +43,10 @@ First, let's see how this data looks on a default ggplot: p1 <- data |> # We'll look at the bookings by race here, # and we'll look by month just to make it easier to see. - count(book_month = floor_date(book_date, "months"), - race) |> + count( + book_month = floor_date(book_date, "months"), + race + ) |> ggplot(aes(x = book_month, y = n, fill = race)) + geom_col() @@ -52,12 +57,14 @@ Next, let's gussy this up with our `ojoThemes` tools. First, let's use the `ojot ```{r ojo_labs} p1 <- p1 + - ojo_labs(analyst_name = "Andrew Bell", - source = "ocdc", - title = "OCDC Bookings by Race", - subtitle = "January 2024 - October 2024", - x = "Month", - y = "Total Booking Events") + ojo_labs( + analyst_name = "Andrew Bell", + source = "ocdc", + title = "OCDC Bookings by Race", + subtitle = "January 2024 - October 2024", + x = "Month", + y = "Total Booking Events" + ) p1 ``` @@ -84,7 +91,7 @@ p1 ## Themes for `gt` tables -This package also has built in themes for tables made with `gt`. You can use these by replacing the normal `gt()` function with one of our themed wrappers (currently `gt_okpi()` and `gt_ojo()`). These have built in arguments for customization: +This package also has built in themes for tables made with `gt`. You can use these by replacing the normal `gt()` function with one of our themed wrappers (currently `gt_okpi()` and `gt_ojo()`). These have built in arguments for customization: * `source` and `analyst_name` (which work just like the `ojo_labs()` function for ggplots) * `title` and `subtitle` (self explanatory) @@ -104,11 +111,13 @@ data |> ```{r gt_okpi} data |> count(race) |> - gt_okpi(title = "OCDC Bookings by Race", - subtitle = "January 2024 - October 2024", - source = "ocdc", - analyst_name = "Andrew Bell", - format_cols = TRUE) + gt_okpi( + title = "OCDC Bookings by Race", + subtitle = "January 2024 - October 2024", + source = "ocdc", + analyst_name = "Andrew Bell", + format_cols = TRUE + ) ``` ...and finally, here's `gt_ojo()`: @@ -116,9 +125,11 @@ data |> ```{r gt_ojo} data |> count(race) |> - gt_ojo(title = "OCDC Bookings by Race", - subtitle = "January 2024 - October 2024", - source = "ocdc", - analyst_name = "Andrew Bell", - format_cols = TRUE) + gt_ojo( + title = "OCDC Bookings by Race", + subtitle = "January 2024 - October 2024", + source = "ocdc", + analyst_name = "Andrew Bell", + format_cols = TRUE + ) ``` From 7f3431fa02bffe5898598c84329a583b8a348e21 Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:35:04 -0600 Subject: [PATCH 25/25] added more horizontal spacing between legend items --- R/theme_ojo.R | 1 + R/theme_okpi.R | 1 + 2 files changed, 2 insertions(+) diff --git a/R/theme_ojo.R b/R/theme_ojo.R index ee2bb88..665f705 100644 --- a/R/theme_ojo.R +++ b/R/theme_ojo.R @@ -107,6 +107,7 @@ theme_ojo_base <- function(base_size = 16, legend.key.size = ggplot2::unit(10L, "pt"), legend.key.height = NULL, legend.key.width = NULL, + legend.key.spacing.x = ggplot2::unit(12L, "pt"), legend.text = ggplot2::element_text(size = base_size * 9.5 / 8.5, vjust = 0.5), diff --git a/R/theme_okpi.R b/R/theme_okpi.R index 9ced00c..23ceea9 100644 --- a/R/theme_okpi.R +++ b/R/theme_okpi.R @@ -35,6 +35,7 @@ theme_okpi_base <- function(base_size = 16, plot.background = ggplot2::element_blank(), legend.background = ggplot2::element_rect(fill = "transparent", colour = NA), legend.key = ggplot2::element_rect(fill = "transparent", colour = NA), + legend.key.spacing.x = ggplot2::unit(12L, "pt"), legend.position = "top", panel.border = ggplot2::element_blank(), panel.grid.major.x = ggplot2::element_blank(),