Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhodge931 committed Dec 15, 2024
1 parent 3c80f72 commit c25d678
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 145 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ggblanket 11.0.0.9000

* Rethought `set_blanket` and `weave_geom_defaults` arguments.
* In `set_blanket`, renamed `reference_line_*` arguments to `reference_*`.
* Added R 4.2.0 dependency.
* Removed `aes_colour_darken`, `aes_colour_lighten`, `aes_fill_darken` and `aes_colour_lighten`.
* Removed `gg_ribbon`, `gg_boxplot`, `gg_crossbar` and `gg_smooth` alpha default to `NA`.
Expand Down
52 changes: 17 additions & 35 deletions R/set_blanket.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,13 @@
#'
#' @param ... Provided to force user argument naming etc.
#' @param mode A ggplot2 theme (e.g. [light_mode_t()] or [dark_mode_r()]) that anticipates `gg_*` side-effects of removing relevant axis line/ticks and gridlines per the `mode_orientation`.
#' @param colour A default hex colour for the colour of geoms.
#' @param colour_text A default hex colour for the colour of the "text" geom.
#' @param colour_label A default hex colour for the colour of the "label" geom.
#' @param colour_hline A default hex colour for the colour of the "hline" geom.
#' @param colour_vline A default hex colour for the colour of the vline" geom.
#' @param fill A default hex colour for the fill of geoms.
#' @param fill_label A default hex colour for the fill of the "label" geom.
#' @param size_text A default size for the "text" geom.
#' @param size_label A default size for the label" geom.
#' @param family_text A default family for the "text" geom.
#' @param family_label A default family for the "label" geom.
#' @param linewidth_hline A default hex colour for the colour of the "hline" geom.
#' @param linewidth_vline A default hex colour for the colour of the "vline" geom.
#' @param colour A default hex colour for the colour of geoms (other than "text", "label", "hline", "vline" and "abline" geoms).
#' @param fill A default hex colour for the fill of geoms (other than "text", "label", "hline", "vline" and "abline" geoms).
#' @param text_colour A default hex colour for the colour of the "text" and "label" geoms.
#' @param text_size A default size for the "text" and "label" geoms.
#' @param text_family A default family for the "text" and "label" geoms.
#' @param reference_colour A default hex colour for the colour of the "hline", "vline" and "abline" geoms.
#' @param reference_linewidth A default hex colour for the colour of the "hline", "vline" and "abline" geoms.
#' @param col_palette_d For a discrete scale, a character vector of hex codes.
#' @param col_palette_c For a continuous scale, a character vector of hex codes.
#' @param col_palette_o For an ordinal scale, a `scales::pal_*()` function.
Expand Down Expand Up @@ -72,18 +66,12 @@ set_blanket <- function(
...,
mode = light_mode_r(),
colour = "#357BA2FF",
colour_text = "#121B24FF",
colour_label = "#FFFFFFFF",
colour_hline = "#121B24FF",
colour_vline = "#121B24FF",
fill = colour,
fill_label = "#121B24FF",
size_text = 11 / 2.835052,
size_label = size_text,
family_text = "",
family_label = family_text,
linewidth_hline = 0.25,
linewidth_vline = 0.25,
text_colour = "#121B24FF",
text_size = 11 / 2.835052,
text_family = "",
reference_colour = "#121B24FF",
reference_linewidth = 0.25,
col_palette_d = jumble,
col_palette_c = viridisLite::mako(n = 9, direction = -1),
col_palette_o = scales::pal_viridis(option = "G", direction = -1),
Expand All @@ -96,18 +84,12 @@ set_blanket <- function(

weave_geom_defaults(
colour = colour,
colour_text = colour_text,
colour_label = colour_label,
colour_hline = colour_hline,
colour_vline = colour_vline,
fill = fill,
fill_label = fill_label,
size_text = size_text,
size_label = size_label,
family_text = family_text,
family_label = family_label,
linewidth_hline = linewidth_hline,
linewidth_vline = linewidth_vline
text_colour = text_colour,
text_size = text_size,
text_family = text_family,
reference_colour = reference_colour,
reference_linewidth = reference_linewidth
)

weave_col_palettes(
Expand Down
46 changes: 17 additions & 29 deletions R/weave.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,23 @@ weave_mode <- function(mode = light_mode_r()) {
#'
#' [ggplot2::update_geom_defaults()] can be used to further fine-tune individual geom defaults.
#'
#' @param colour A default hex colour for the colour of geoms.
#' @param colour_text A default hex colour for the colour of the "text" geom.
#' @param colour_label A default hex colour for the colour of the "label" geom.
#' @param colour_hline A default hex colour for the colour of the "hline" geom.
#' @param colour_vline A default hex colour for the colour of the vline" geom.
#' @param fill A default hex colour for the fill of geoms.
#' @param fill_label A default hex colour for the fill of the "label" geom.
#' @param size_text A default size for the "text" geom.
#' @param size_label A default size for the label" geom.
#' @param family_text A default family for the "text" geom.
#' @param family_label A default family for the "label" geom.
#' @param linewidth_hline A default hex colour for the colour of the "hline" geom.
#' @param linewidth_vline A default hex colour for the colour of the "vline" geom.
#' @param colour A default hex colour for the colour of geoms (other than "text", "label", "hline", "vline" and "abline" geoms).
#' @param fill A default hex colour for the fill of geoms (other than "text", "label", "hline", "vline" and "abline" geoms).
#' @param text_colour A default hex colour for the colour of the "text" and "label" geoms.
#' @param text_size A default size for the "text" and "label" geoms.
#' @param text_family A default family for the "text" and "label" geoms.
#' @param reference_colour A default hex colour for the colour of the "hline", "vline" and "abline" geoms.
#' @param reference_linewidth A default hex colour for the colour of the "hline", "vline" and "abline" geoms.
#'
#' @export
weave_geom_defaults <- function(
colour = "#357BA2FF",
colour_text = "#121B24FF",
colour_label = "#FFFFFFFF",
colour_hline = "#121B24FF",
colour_vline = "#121B24FF",
fill = colour,
fill_label = "#121B24FF",
size_text = 11 / 2.835052,
size_label = 11 / 2.835052,
family_text = "",
family_label = "",
linewidth_hline = 0.25,
linewidth_vline = 0.25
text_colour = "#121B24FF",
text_size = 11 / 2.835052,
text_family = "",
reference_colour = "#121B24FF",
reference_linewidth = 0.25
) {

#polygons
Expand All @@ -83,7 +71,6 @@ weave_geom_defaults <- function(
ggplot2::update_geom_defaults("hex", ggplot2::aes(fill = !!fill, linewidth = 0))

#lines
ggplot2::update_geom_defaults("abline", ggplot2::aes(colour = !!colour, linewidth = 0.66))
ggplot2::update_geom_defaults("contour", ggplot2::aes(colour = !!colour, linewidth = 0.66))
ggplot2::update_geom_defaults("curve", ggplot2::aes(colour = !!colour, linewidth = 0.66))
ggplot2::update_geom_defaults("density2d", ggplot2::aes(colour = !!colour, linewidth = 0.66))
Expand All @@ -103,12 +90,13 @@ weave_geom_defaults <- function(
ggplot2::update_geom_defaults("pointrange", ggplot2::aes(colour = !!colour, fill = !!fill, linewidth = 0.66, size = 0.2)) # 1.5 / 7.5

#hline & vline
ggplot2::update_geom_defaults("hline", ggplot2::aes(colour = !!colour_hline, linewidth = !!linewidth_hline))
ggplot2::update_geom_defaults("vline", ggplot2::aes(colour = !!colour_vline, linewidth = !!linewidth_vline))
ggplot2::update_geom_defaults("abline", ggplot2::aes(colour = !!reference_colour, linewidth = !!reference_linewidth))
ggplot2::update_geom_defaults("hline", ggplot2::aes(colour = !!reference_colour, linewidth = !!reference_linewidth))
ggplot2::update_geom_defaults("vline", ggplot2::aes(colour = !!reference_colour, linewidth = !!reference_linewidth))

#text and label
ggplot2::update_geom_defaults("text", ggplot2::aes(colour = !!colour_text, size = !!size_text, family = !!family_text))
ggplot2::update_geom_defaults("label", ggplot2::aes(colour = !!colour_label, fill = !!fill_label, size = !!size_label, family = !!family_label))
ggplot2::update_geom_defaults("text", ggplot2::aes(colour = !!text_colour, size = !!text_size, family = !!text_family))
ggplot2::update_geom_defaults("label", ggplot2::aes(colour = !!text_colour, size = !!text_size, family = !!text_family))
}

#' Set a discrete colour and fill palettes
Expand Down
42 changes: 12 additions & 30 deletions man/set_blanket.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 12 additions & 30 deletions man/weave_geom_defaults.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tests/testthat/_snaps/article-demo-light/gg-label.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/test-article-demo-light.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ test_that(test_name, {
size = 3.53,
y_expand_limits = 0,
y_label = "Miles per gallon",
col_palette = c(orange, "white", teal),
# col_palette = c(orange, "white", teal),
)

vdiffr::expect_doppelganger(test_name, p)
Expand Down
Loading

0 comments on commit c25d678

Please sign in to comment.