Browse Source

more themes and helpers

master
boB Rudis 2 months ago
parent
commit
1eaf024f45
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
42 changed files with 4665 additions and 370 deletions
  1. +3
    -2
      DESCRIPTION
  2. +15
    -0
      NAMESPACE
  3. +31
    -25
      R/install-fonts.R
  4. +62
    -0
      R/preview-variant.R
  5. +2
    -1
      R/reconfigure-font.R
  6. +95
    -0
      R/reset-ggplot2-defaults.R
  7. +0
    -278
      R/roboto-condensed.R
  8. +339
    -0
      R/scales.R
  9. +278
    -0
      R/theme-gs.R
  10. +2
    -1
      R/theme-inter.R
  11. +278
    -0
      R/theme-rc.R
  12. +11
    -0
      R/utils-pipe.R
  13. +110
    -0
      R/x-font-reg.R
  14. +66
    -48
      R/zzz.R
  15. +62
    -0
      README.Rmd
  16. +126
    -11
      README.md
  17. +2574
    -0
      Rplot.svg
  18. BIN
      inst/fonts/goldman-sans-condensed/GoldmanSansCd_Bd.ttf
  19. BIN
      inst/fonts/goldman-sans-condensed/GoldmanSansCd_Rg.ttf
  20. BIN
      man/figures/README-dark-mode-01-1.png
  21. BIN
      man/figures/README-dark-mode-01-gs-1.png
  22. BIN
      man/figures/README-dark-mode-01-rc-1.png
  23. BIN
      man/figures/README-dark-mode-02-1.png
  24. BIN
      man/figures/README-light-mode-01-1.png
  25. BIN
      man/figures/README-light-mode-01-gs-1.png
  26. BIN
      man/figures/README-light-mode-01-rc-1.png
  27. BIN
      man/figures/README-light-mode-02-1.png
  28. BIN
      man/figures/README-preview-00-1.png
  29. BIN
      man/figures/README-preview-01-1.png
  30. BIN
      man/figures/README-preview-02-1.png
  31. +41
    -0
      man/gs_pkg.Rd
  32. +23
    -0
      man/install_goldman_sans.Rd
  33. +22
    -0
      man/install_roboto_condensed.Rd
  34. +3
    -3
      man/inter_pkg.Rd
  35. +12
    -0
      man/pipe.Rd
  36. +51
    -0
      man/preview_variant.Rd
  37. +40
    -0
      man/rc_pkg.Rd
  38. +11
    -0
      man/reset_ggplot2_defaults.Rd
  39. +172
    -0
      man/scale_x_percent.Rd
  40. +117
    -0
      man/theme_gs.Rd
  41. +2
    -1
      man/theme_inter.Rd
  42. +117
    -0
      man/theme_rc.Rd

+ 3
- 2
DESCRIPTION View File

@ -30,7 +30,7 @@ Depends:
R (>= 3.6.0)
Imports:
ragg (>= 0.4.1),
systemfonts (>= 1.0.1),
systemfonts (>= 1.0.1),
textshaping (>= 0.3.0),
ggplot2 (>= 3.3.2),
grid (>= 4.0.4),
@ -38,6 +38,7 @@ Imports:
scales (>= 1.1.1),
tools,
ggtext (>= 0.1.0),
rstudioapi
rstudioapi,
magrittr
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1

+ 15
- 0
NAMESPACE View File

@ -1,16 +1,30 @@
# Generated by roxygen2: do not edit by hand
export("%>%")
export(adaptive_color)
export(elb)
export(ell)
export(elr)
export(elt)
export(gs_pkg)
export(gsc_pkg)
export(install_goldman_sans)
export(install_inter)
export(install_roboto_condensed)
export(inter_pkg)
export(preview_variant)
export(rc_pkg)
export(reconfigure_font)
export(reset_ggplot2_defaults)
export(scale_x_comma)
export(scale_x_percent)
export(scale_y_comma)
export(scale_y_percent)
export(theme_background_color)
export(theme_foreground_color)
export(theme_gs)
export(theme_inter)
export(theme_rc)
import(ggplot2)
import(ggtext)
import(grDevices)
@ -20,4 +34,5 @@ import(scales)
import(systemfonts)
import(textshaping)
import(tools)
importFrom(magrittr,"%>%")
importFrom(rstudioapi,getThemeInfo)

+ 31
- 25
R/install-fonts.R View File

@ -33,32 +33,38 @@ install_font <- function(family_name, sub_dir) {
}
# #' Install Goldman Sans (Condensed)
# #'
# #' Goldman Sans is a clean, modern typeface designed for dense data-rich
# #' environments. From open letter shapes, enlarged x-height, and optical
# #' balancing of individual letterforms, we designed Goldman Sans with
# #' clarity in mind. Both normal and condensed versions are provided.
# #'
# #' @export
# # install_goldman_sans <- function() {
# install_font("Goldman Sans (Condensed)", "goldman-sans")
# }
#' Install Goldman Sans (Condensed)
#'
#' Goldman Sans is a clean, modern typeface designed for dense data-rich
#' environments. From open letter shapes, enlarged x-height, and optical
#' balancing of individual letterforms, we designed Goldman Sans with
#' clarity in mind. Both normal and condensed versions are provided.
#'
#' @export
#' @note [Goldman Sans Restricted Font License](https://design.gs.com/d/legal/goldman-sans-license)
#' @references [Goldman Sans](https://design.gs.com/d/story/goldman-sans/)
#' @examples
#' install_goldman_sans()
install_goldman_sans <- function() {
install_font("Goldman Sans (Condensed)", "goldman-sans")
}
# #' Install Roboto Condensed
# #'
# #' Roboto has a dual nature. It has a mechanical skeleton and the forms are
# #' largely geometric. At the same time, the font features friendly and open
# #' curves. While some grotesks distort their letterforms to force a rigid rhythm,
# #' Roboto doesn’t compromise, allowing letters to be settled into their natural
# #' width. This makes for a more natural reading rhythm more commonly found in
# #' humanist and serif types.
# #'
# #' @note [Apache License, Version 2.0.](http://www.apache.org/licenses/LICENSE-2.0)
# #' @export
# install_roboto_condensed <- function() {
# install_font("Roboto Condensed", "roboto-condensed")
# }
#' Install Roboto Condensed
#'
#' Roboto has a dual nature. It has a mechanical skeleton and the forms are
#' largely geometric. At the same time, the font features friendly and open
#' curves. While some grotesks distort their letterforms to force a rigid rhythm,
#' Roboto doesn’t compromise, allowing letters to be settled into their natural
#' width. This makes for a more natural reading rhythm more commonly found in
#' humanist and serif types.
#'
#' @note [Apache License, Version 2.0.](http://www.apache.org/licenses/LICENSE-2.0)
#' @export
#' @examples
#' install_roboto_condensed()
install_roboto_condensed <- function() {
install_font("Roboto Condensed", "roboto-condensed")
}
#' Install Inter
#'


+ 62
- 0
R/preview-variant.R View File

@ -0,0 +1,62 @@
#' Preview numbers, kerning, and ligatures from font variants you create
#'
#' Use this function to preview the special features of fonts you create
#' including how well the default kerning ruls work, how tabular numbers
#' behave, and whether or not modern, fun ligatures are supported. Change
#' the `test_label` if you wish to use a custom preview string.
#'
#' @param font_variant a font variant object created with [reconfigure_font()]
#' @param font_size passed to [ggplot2::geom_text()]
#' @param test_label a specially designed preview string to showcase some
#' specific font features
#' @return A ggplot2 object
#' @export
#' @examples
#' reconfigure_font(
#' family = "Trattatello",
#' width = "normal",
#' ligatures = "discretionary",
#' calt = 1, tnum = 1, case = 1,
#' dlig = 1, kern = 1,
#' zero = 0, salt = 0
#' ) -> trat
#'
#' preview_variant(trat)
#'
#' reconfigure_font(
#' family = "Barlow",
#' width = "normal",
#' ligatures = "standard",
#' tnum = 1, kern = 1
#' ) -> barlow
#'
#' preview_variant(barlow)
preview_variant <- function(font_variant, font_size = 5,
test_label = "Lorem Ipsum dolor sit amet consectetur. => A⃝\n−0+1:2~3,456789\n−9+8:7~6,543210") {
ggplot() +
geom_text(
data = data.frame(
x = rep(1, length(font_variant)),
y = 2 * (0:(length(font_variant)-1)),
family = unlist(font_variant, use.names = FALSE)
),
aes(x = x, y = y, label = test_label, family = family),
size = font_size, lineheight = 0.875, color = "black"
) +
scale_y_continuous(expand = c(0, 2)) +
labs(title = attr(font_variant, "family")) +
theme_minimal() +
theme(
plot.title = element_text(family = font_variant$normal, size = 9, hjust = 0.5)
) +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
) +
theme(
axis.text = element_blank(),
axis.title = element_blank()
)
}

+ 2
- 1
R/reconfigure-font.R View File

@ -80,8 +80,9 @@ reconfigure_font <- function(family, width = "normal",
idx_nam <- as.character(fam$weight[idx])
if (fam$italic[idx]) idx_nam <- sprintf("%s_italic", idx_nam)
if (fam$monospace[idx]) idx_nam <- sprintf("%s_mono", idx_nam)
if (fam$style[idx] == "Light") idx_nam <- sprintf("%s_light", idx_nam)
ret[[idx_nam]] <- tmp_nam
(ret[[idx_nam]] <- tmp_nam)
register_variant(
name = tmp_nam,


+ 95
- 0
R/reset-ggplot2-defaults.R View File

@ -0,0 +1,95 @@
list(Geom = structure(list(), .Names = character(0), class = "uneval"),
GeomAbline = structure(list(colour = "black", size = 0.5,
linetype = 1, alpha = NA), class = "uneval"), GeomAnnotationMap = structure(list(
colour = "NA", fill = "grey20", size = 0.5, linetype = 1,
alpha = NA, subgroup = NULL), class = "uneval"), GeomArea = structure(list(
colour = NA, fill = "grey20", size = 0.5, linetype = 1,
alpha = NA), class = "uneval"), GeomBar = structure(list(
colour = NA, fill = "grey35", size = 0.5, linetype = 1,
alpha = NA), class = "uneval"), GeomBlank = structure(list(), .Names = character(0), class = "uneval"),
GeomBoxplot = structure(list(weight = 1, colour = "grey20",
fill = "white", size = 0.5, alpha = NA, shape = 19, linetype = "solid"), class = "uneval"),
GeomCol = structure(list(colour = NA, fill = "grey35", size = 0.5,
linetype = 1, alpha = NA), class = "uneval"), GeomContour = structure(list(
weight = 1, colour = "#3366FF", size = 0.5, linetype = 1,
alpha = NA), class = "uneval"), GeomContourFilled = structure(list(
colour = "NA", fill = "grey20", size = 0.5, linetype = 1,
alpha = NA, subgroup = NULL), class = "uneval"), GeomCrossbar = structure(list(
colour = "black", fill = NA, size = 0.5, linetype = 1,
alpha = NA), class = "uneval"), GeomCurve = structure(list(
colour = "black", size = 0.5, linetype = 1, alpha = NA), class = "uneval"),
GeomCustomAnn = structure(list(xmin = -Inf, xmax = Inf, ymin = -Inf,
ymax = Inf), class = "uneval"), GeomDensity = list(fill = NA,
weight = 1, colour = "black", alpha = NA, size = 0.5,
linetype = 1), GeomDensity2d = structure(list(colour = "#3366FF",
size = 0.5, linetype = 1, alpha = NA), class = "uneval"),
GeomDensity2dFilled = structure(list(colour = "NA", fill = "grey20",
size = 0.5, linetype = 1, alpha = NA, subgroup = NULL), class = "uneval"),
GeomDotplot = structure(list(colour = "black", fill = "black",
alpha = NA, stroke = 1, linetype = "solid"), class = "uneval"),
GeomErrorbar = structure(list(colour = "black", size = 0.5,
linetype = 1, width = 0.5, alpha = NA), class = "uneval"),
GeomErrorbarh = structure(list(colour = "black", size = 0.5,
linetype = 1, height = 0.5, alpha = NA), class = "uneval"),
GeomFunction = structure(list(colour = "black", size = 0.5,
linetype = 1, alpha = NA), class = "uneval"), GeomHex = structure(list(
colour = NA, fill = "grey50", size = 0.5, linetype = 1,
alpha = NA), class = "uneval"), GeomHline = structure(list(
colour = "black", size = 0.5, linetype = 1, alpha = NA), class = "uneval"),
GeomLabel = structure(list(colour = "black", fill = "white",
size = 3.88, angle = 0, hjust = 0.5, vjust = 0.5, alpha = NA,
family = "", fontface = 1, lineheight = 1.2), class = "uneval"),
GeomLine = structure(list(colour = "black", size = 0.5, linetype = 1,
alpha = NA), class = "uneval"), GeomLinerange = structure(list(
colour = "black", size = 0.5, linetype = 1, alpha = NA), class = "uneval"),
GeomLogticks = structure(list(colour = "black", size = 0.5,
linetype = 1, alpha = 1), class = "uneval"), GeomMap = structure(list(
colour = "NA", fill = "grey20", size = 0.5, linetype = 1,
alpha = NA, subgroup = NULL), class = "uneval"), GeomPath = structure(list(
colour = "black", size = 0.5, linetype = 1, alpha = NA), class = "uneval"),
GeomPoint = structure(list(shape = 19, colour = "black",
size = 1.5, fill = NA, alpha = NA, stroke = 0.5), class = "uneval"),
GeomPointrange = structure(list(colour = "black", size = 0.5,
linetype = 1, shape = 19, fill = NA, alpha = NA, stroke = 1), class = "uneval"),
GeomPolygon = structure(list(colour = "NA", fill = "grey20",
size = 0.5, linetype = 1, alpha = NA, subgroup = NULL), class = "uneval"),
GeomQuantile = list(weight = 1, colour = "#3366FF", size = 0.5,
linetype = 1, alpha = NA), GeomRaster = structure(list(
fill = "grey20", alpha = NA), class = "uneval"), GeomRasterAnn = structure(list(),
.Names = character(0), class = "uneval"),
GeomRect = structure(list(colour = NA, fill = "grey35", size = 0.5,
linetype = 1, alpha = NA), class = "uneval"), GeomRibbon = structure(list(
colour = NA, fill = "grey20", size = 0.5, linetype = 1,
alpha = NA), class = "uneval"), GeomRug = structure(list(
colour = "black", size = 0.5, linetype = 1, alpha = NA), class = "uneval"),
GeomSegment = structure(list(colour = "black", size = 0.5,
linetype = 1, alpha = NA), class = "uneval"), GeomSf = structure(list(
shape = NULL, colour = NULL, fill = NULL, size = NULL,
linetype = 1, alpha = NA, stroke = 0.5), class = "uneval"),
GeomSmooth = structure(list(colour = "#3366FF", fill = "grey60",
size = 1, linetype = 1, weight = 1, alpha = 0.4), class = "uneval"),
GeomSpoke = structure(list(colour = "black", size = 0.5,
linetype = 1, alpha = NA), class = "uneval"), GeomStep = structure(list(
colour = "black", size = 0.5, linetype = 1, alpha = NA), class = "uneval"),
GeomText = structure(list(colour = "black", size = 3.88,
angle = 0, hjust = 0.5, vjust = 0.5, alpha = NA, family = "",
fontface = 1, lineheight = 1.2), class = "uneval"), GeomTile = structure(list(
fill = "grey20", colour = NA, size = 0.1, linetype = 1,
alpha = NA, width = NA, height = NA), class = "uneval"),
GeomViolin = structure(list(weight = 1, colour = "grey20",
fill = "white", size = 0.5, alpha = NA, linetype = "solid"), class = "uneval"),
GeomVline = structure(list(colour = "black", size = 0.5,
linetype = 1, alpha = NA), class = "uneval")) -> .ggplot2_default_aes
#' Restore all ggplot2 geom to default aesthetics
#'
#' @export
reset_ggplot2_defaults <- function() {
for (geom in names(.ggplot2_default_aes)) {
ggplot2::update_geom_defaults(
geom = get(geom), .ggplot2_default_aes[[geom]]
)
}
}

+ 0
- 278
R/roboto-condensed.R View File

@ -1,278 +0,0 @@
# #' ggplot2 Theme Based On The Roboto Condensed Font Family
# #'
# #' Uses the built-in [roboto_pkg] custom font.
# #'
# #' - `background_colour` dark mode is "`#121212`" else "`white`"
# #' - `foreground_colour` dark mode is "`#e1e1e1`" else "`#262626`"
# #' - `grid_col` dark mode is "`#606367`" else "`#cccccc`"
# #' - `axis_col` dark mode is "`#606367`" else "`#2b2b2b`"
# #'
# #' @note this function updates `Geom` defaults
# #' @param base_size base font size
# #' @param line_height default line height
# #' @param plot_title_size plot title size
# #' @param plot_title_position plot title position
# #' @param plot_title_margin plot title margin
# #' @param subtitle_size subtitle size
# #' @param subtitle_margin subtitle margin
# #' @param strip_text_size strip text size
# #' @param strip_placement strip placement
# #' @param caption_size caption size
# #' @param caption_margin caption margin
# #' @param axis_text_size axis text size
# #' @param axis_title_size axis title size
# #' @param axis_title_just axis title just
# #' @param text_geom_size text geom size
# #' @param panel_spacing panel spacing
# #' @param plot_margin plot margin
# #' @param grid_col grid col
# #' @param grid grid
# #' @param axis_col axis col
# #' @param axis axis
# #' @param ticks ticks
# #' @return ggplot2 theme
# #' @export
# #' @examples
# #' ggplot() +
# #' geom_point(
# #' data = mtcars,
# #' aes(mpg, wt)
# #' ) +
# #' geom_label(
# #' aes(
# #' x = 30, y = 4.5,
# #' label = "A fairly useless\nannotation that\nuses the custom\nInter variant\nby default."
# #' ),
# #' label.size = 0
# #' ) +
# #' labs(
# #' x = "Fuel efficiency (mpg)", y = "Weight (tons)",
# #' title = "Seminal ggplot2 scatterplot example",
# #' subtitle = "A plot that is only useful for demonstration purposes",
# #' caption = "Brought to you by the letter 'g'"
# #' ) +
# #' theme_inter(grid = "XY")
# theme_inter <- function(
# base_size = 10,
# line_height = 0.875,
# plot_title_size = 18,
# plot_title_position = "panel",
# plot_title_margin = 10,
# subtitle_size = 12,
# subtitle_margin = 12,
# strip_text_size = 12,
# strip_placement = "outer",
# caption_size = 9,
# caption_margin = 10,
# axis_text_size = base_size,
# axis_title_size = 9,
# axis_title_just = "rt",
# panel_spacing = grid::unit(2, "lines"),
# plot_margin = margin(30, 30, 30, 30),
# mode = c("light", "dark", "rstudio"),
# background_colour = theme_background_color(mode, light = "white", dark = "#121212"),
# foreground_colour = theme_foreground_color(mode, light = "#262626", dark = "#e1e1e1"),
# grid_col = theme_foreground_color(mode, light = "#cccccc", dark = "#606367"),
# axis_col = theme_foreground_color(mode, light = "#2b2b2b", dark = "#606367"),
# grid = TRUE,
# axis = FALSE,
# ticks = FALSE) {
#
# base_family <- inter_pkg$normal
# plot_title_family <- inter_pkg$ultrabold
# subtitle_family <- inter_pkg$medium
# strip_text_family <- inter_pkg$semibold
# axis_text_family <- inter_pkg$normal
# caption_family <- inter_pkg$normal
# axis_title_family <- inter_pkg$medium
#
# c(
# "GeomRect", "GeomLabel", "GeomTile", "GeomViolin"
# ) -> has_reverse_cols
#
# geoms <- ls(pattern = '^Geom', env = as.environment('package:ggplot2'))
#
# for (geom in geoms) {
#
# update_geom_defaults(
# geom = get(geom),
# new = list(
# arrow.fill = background_colour,
# outlier.colour = foreground_colour,
# outlier.fill = background_colour,
# colour = foreground_colour,
# fill = if (geom %in% c(has_reverse_cols)) background_colour else NA,
# family = base_family,
# lineheight = line_height
# )
# )
#
# }
#
# theme_minimal(
# base_family = base_family,
# base_size = base_size,
# ) +
# theme(
# rect = element_rect(colour = foreground_colour, fill = background_colour),
# line = element_line(colour = foreground_colour),
# title = element_text(colour = foreground_colour),
# legend.background = element_blank(),
# legend.key = element_blank(),
# legend.text = element_text(colour = foreground_colour, family = inter_pkg$medium),
# legend.title = element_text(colour = foreground_colour, family = inter_pkg$semibold)
# ) -> ret
#
#
# if (inherits(grid, "character") | grid == TRUE) {
#
# ret +
# theme(
# panel.grid = element_line(colour = grid_col, size = 0.2),
# panel.grid.major = element_line(colour = grid_col, size = 0.2),
# panel.grid.minor = element_line(colour = grid_col, size = 0.15)
# ) -> ret
#
# if (inherits(grid, "character")) {
# if (regexpr("X", grid)[1] < 0) ret <- ret + theme(panel.grid.major.x = element_blank())
# if (regexpr("Y", grid)[1] < 0) ret <- ret + theme(panel.grid.major.y = element_blank())
# if (regexpr("x", grid)[1] < 0) ret <- ret + theme(panel.grid.minor.x = element_blank())
# if (regexpr("y", grid)[1] < 0) ret <- ret + theme(panel.grid.minor.y = element_blank())
# }
#
# } else {
# ret <- ret + theme(panel.grid = element_blank())
# }
#
# if (inherits(axis, "character") | axis == TRUE) {
# ret <- ret + theme(axis.line = element_line(colour = axis_col, size = 0.15))
# if (inherits(axis, "character")) {
# axis <- tolower(axis)
# if (regexpr("x", axis)[1] < 0) {
# ret <- ret + theme(axis.line.x = element_blank())
# } else {
# ret <- ret + theme(axis.line.x = element_line(colour = axis_col, size = 0.15))
# }
# if (regexpr("y", axis)[1] < 0) {
# ret <- ret + theme(axis.line.y = element_blank())
# } else {
# ret <- ret + theme(axis.line.y = element_line(colour = axis_col, size = 0.15))
# }
# } else {
# ret + theme(
# axis.line.x = element_line(colour = axis_col, size = 0.15),
# axis.line.y = element_line(colour = axis_col, size = 0.15)
# ) -> ret
# }
# } else {
# ret <- ret + theme(axis.line = element_blank())
# }
#
# if (!ticks) {
#
# ret + theme(
# axis.ticks = element_blank(),
# axis.ticks.x = element_blank(),
# axis.ticks.y = element_blank()
# ) -> ret
#
# } else {
#
# ret + theme(
# axis.ticks = element_line(size = 0.15),
# axis.ticks.x = element_line(size = 0.15),
# axis.ticks.y = element_line(size = 0.15),
# axis.ticks.length = grid::unit(5, "pt")
# ) -> ret
#
# }
#
# xj <- switch(tolower(substr(axis_title_just, 1, 1)), b = 0, l = 0, m = 0.5, c = 0.5, r = 1, t = 1)
# yj <- switch(tolower(substr(axis_title_just, 2, 2)), b = 0, l = 0, m = 0.5, c = 0.5, r = 1, t = 1)
#
# ret +
# theme(
# axis.text.x = element_text(size = axis_text_size, margin = margin(t = 0), lineheight = line_height),
# axis.text.x.top = element_text(size = axis_text_size, margin = margin(t = 0), lineheight = line_height),
# axis.text.x.bottom = element_text(size = axis_text_size, margin = margin(t = 0), lineheight = line_height),
#
# axis.text.y = element_text(size = axis_text_size, margin = margin(r = 0), lineheight = line_height),
# axis.text.y.left = element_text(size = axis_text_size, margin = margin(r = 0), lineheight = line_height),
# axis.text.y.right = element_text(size = axis_text_size, margin = margin(r = 0), lineheight = line_height),
#
# axis.title = element_text(
# size = axis_title_size,
# family = axis_title_family, lineheight = line_height
# ),
#
# axis.title.x = element_text(
# hjust = xj, size = axis_title_size,
# family = axis_title_family, lineheight = line_height
# ),
# axis.title.x.top = element_text(
# hjust = xj, size = axis_title_size,
# family = axis_title_family, lineheight = line_height
# ),
# axis.title.x.bottom = element_text(
# hjust = xj, size = axis_title_size,
# family = axis_title_family, lineheight = line_height
# ),
#
# axis.title.y = element_text(
# hjust = yj, size = axis_title_size,
# family = axis_title_family, lineheight = line_height
# ),
# axis.title.y.left = element_text(
# hjust = yj, size = axis_title_size,
# family = axis_title_family, lineheight = line_height
# ),
# axis.title.y.right = element_text(
# hjust = yj, size = axis_title_size, angle = 90,
# family = axis_title_family, lineheight = line_height
# ),
#
# strip.placement = strip_placement,
# strip.text = element_text(
# hjust = 0, size = strip_text_size, color = foreground_colour,
# family = strip_text_family, lineheight = line_height
# ),
# strip.text.x = element_text(
# hjust = 0, size = strip_text_size, color = foreground_colour,
# family = strip_text_family, lineheight = line_height
# ),
# strip.background = element_rect(
# fill = background_colour, color = NA
# ),
# strip.background.x = element_rect(
# fill = background_colour, color = NA
# ),
# strip.background.y = element_rect(
# fill = background_colour, color = NA
# ),
# strip.text.y = element_text(
# hjust = 0, size = strip_text_size, color = foreground_colour,
# family = strip_text_family, lineheight = line_height
# ),
# panel.spacing = panel_spacing,
# panel.background = element_rect(color = NA, fill = background_colour),
# plot.background = element_rect(color = NA, fill = background_colour),
# plot.title.position = plot_title_position,
# plot.margin = plot_margin,
# plot.title = element_text(
# hjust = 0, size = plot_title_size, margin = margin(b = plot_title_margin),
# family = plot_title_family, lineheight = line_height
# ),
# plot.subtitle = element_text(
# hjust = 0, size = subtitle_size, margin = margin(b = subtitle_margin),
# family = subtitle_family, lineheight = line_height
# ),
# plot.caption = element_text(
# hjust = 1, size = caption_size, margin = margin(t = caption_margin),
# family = caption_family, lineheight = line_height
# ),
# ) -> ret
#
# ret
#
# }

+ 339
- 0
R/scales.R View File

@ -0,0 +1,339 @@
# Stolen from ggplot2
is.waive <- function (x) { inherits(x, "waiver") }
is.sec_axis <- function (x) { inherits(x, "AxisSecondary") }
is.formula <- function (x) { inherits(x, "formula") }
#' X & Y scales with opinionated pre-sets for percent & comma label formats
#'
#' The `_comma` ones set comma format for axis text and `expand=c(0,0)` (you need to set limits).
#'
#' The `_percent` ones set precent format for axis text and `expand=c(0,0)` (you need to set limits).
#'
#' @md
#' @param name The name of the scale. Used as axis or legend title. If
#' `waiver()`, the default, the name of the scale is taken from the first
#' mapping used for that aesthetic. If `NULL`, the legend title will be
#' omitted.
#' @param breaks One of:
#' - `NULL` for no breaks
#' - `waiver()` for the default breaks computed by the
#' transformation object
#' - A numeric vector of positions
#' - A function that takes the limits as input and returns breaks
#' as output
#' @param minor_breaks One of:
#' - `NULL` for no minor breaks
#' - `waiver()` for the default breaks (one minor break between
#' each major break)
#' - A numeric vector of positions
#' - A function that given the limits returns a vector of minor breaks.
#' @param guide guide A function used to create a guide or its name. See [guides()] for more information.
#' @param n.breaks An integer guiding the number of major breaks. The algorithm may choose a
#' slightly different number to ensure nice break labels. Will only have an effect if
#' `breaks = waiver()`. Use NULL to use the default number of breaks given by the transformation.
#' @param labels Specifying overrides the default format (i.e. you really don't
#' want to do that). `NULL` means no labels.
#' @param limits A numeric vector of length two providing limits of the scale.
#' Use `NA` to refer to the existing minimum or maximum.
#' @param oob Function that handles limits outside of the scale limits
#' (out of bounds). The default replaces out of bounds values with NA.
#' @param na.value If `na.translate = TRUE`, what value aesthetic
#' value should missing be displayed as? Does not apply to position scales
#' where `NA` is always placed at the far right.
#' @param expand same as in ggplot2
#' @param trans Either the name of a transformation object, or the
#' object itself. Built-in transformations include "asn", "atanh",
#' "boxcox", "exp", "identity", "log", "log10", "log1p", "log2",
#' "logit", "probability", "probit", "reciprocal", "reverse" and "sqrt".
#' @param position The position of the axis. "left" or "right" for vertical
#' scales, "top" or "bottom" for horizontal scales
#' @param sec.axis specify a secondary axis
#' @export
scale_x_percent <- function(name = waiver(),
breaks = waiver(),
minor_breaks = waiver(),
guide = waiver(),
n.breaks = NULL,
labels,
limits = NULL,
expand = c(0.01,0),
oob = censor,
na.value = NA_real_,
trans = "identity",
position = "bottom",
sec.axis = waiver(),
accuracy = 1,
scale = 100,
prefix = "",
suffix = "%",
big.mark = " ",
decimal.mark = ".",
trim = TRUE, ...) {
if (missing(labels)) {
scales::percent_format(
accuracy = accuracy,
scale = scale,
prefix = prefix,
suffix = suffix,
big.mark = big.mark,
decimal.mark = decimal.mark,
trim = trim,
...
) -> labels
}
ggplot2::continuous_scale(
aesthetics = c(
"x", "xmin", "xmax", "xend", "xintercept", "xmin_final",
"xmax_final", "xlower", "xmiddle", "xupper", "x0"
),
scale_name = "position_c",
palette = identity,
name = name,
breaks = breaks,
n.breaks = n.breaks,
minor_breaks = minor_breaks,
labels = labels,
limits = limits,
expand = expand,
oob = oob,
na.value = na.value,
trans = trans,
guide = guide,
position = position,
super = ScaleContinuousPosition
) -> sc
if (!is.waive(sec.axis)) {
if (is.formula(sec.axis)) sec.axis <- sec_axis(sec.axis)
if (!is.sec_axis(sec.axis)) stop("Secondary axes must be specified using 'sec_axis()'")
sc$secondary.axis <- sec.axis
}
sc
}
#' @rdname scale_x_percent
#' @export
scale_y_percent <- function(name = waiver(),
breaks = waiver(),
minor_breaks = waiver(),
guide = waiver(),
n.breaks = NULL,
labels,
limits = NULL,
expand = c(0.01,0),
oob = censor,
na.value = NA_real_,
trans = "identity",
position = "left",
sec.axis = waiver(),
accuracy = 1,
scale = 100,
prefix = "",
suffix = "%",
big.mark = " ",
decimal.mark = ".",
trim = TRUE, ...) {
if (missing(labels)) {
scales::percent_format(
accuracy = accuracy,
scale = scale,
prefix = prefix,
suffix = suffix,
big.mark = big.mark,
decimal.mark = decimal.mark,
trim = trim,
...
) -> labels
}
ggplot2::continuous_scale(
aesthetics = c(
"y", "ymin", "ymax", "yend", "yintercept",
"ymin_final", "ymax_final", "lower", "middle", "upper"
),
scale_name = "position_c",
palette = identity,
name = name,
breaks = breaks,
n.breaks = n.breaks,
minor_breaks = minor_breaks,
labels = labels,
limits = limits,
expand = expand,
oob = oob,
na.value = na.value,
trans = trans,
guide = guide,
position = position,
super = ScaleContinuousPosition
) -> sc
if (!is.waive(sec.axis)) {
if (is.formula(sec.axis)) sec.axis <- ggplot2::sec_axis(sec.axis)
if (!is.sec_axis(sec.axis)) stop("Secondary axes must be specified using 'sec_axis()'")
sc$secondary.axis <- sec.axis
}
sc
}
#' @rdname scale_x_percent
#' @param accuracy,scale,prefix,suffix,big.mark,decimal.mark,trim See
#' [scales::comma_format()] or [scales::percent_format()]
#' @param ... passed on to [scales::comma_format()] or [scales::percent_format()]
#' @export
scale_x_comma <- function(name = waiver(),
breaks = waiver(),
minor_breaks = waiver(),
guide = waiver(),
n.breaks = NULL,
labels,
limits = NULL,
expand = c(0.01,0),
oob = censor,
na.value = NA_real_,
trans = "identity",
position = "bottom",
sec.axis = waiver(),
accuracy = 1,
scale = 1,
prefix = "",
suffix = "",
big.mark = ",",
decimal.mark = ".",
trim = TRUE,
...) {
if (missing(labels)) {
scales::comma_format(
accuracy = accuracy,
scale = scale,
prefix = prefix,
suffix = suffix,
big.mark = big.mark,
decimal.mark = decimal.mark,
trim = trim,
...
) -> labels
}
ggplot2::continuous_scale(
aesthetics = c(
"x", "xmin", "xmax", "xend", "xintercept",
"xmin_final", "xmax_final",
"xlower", "xmiddle", "xupper"
),
scale_name = "position_c",
palette = identity,
name = name,
breaks = breaks,
n.breaks = n.breaks,
minor_breaks = minor_breaks,
labels = labels,
limits = limits,
expand = expand,
oob = oob,
na.value = na.value,
trans = trans,
guide = guide,
position = position,
super = ScaleContinuousPosition
) -> sc
if (!is.waive(sec.axis)) {
if (is.formula(sec.axis)) sec.axis <- ggplot2::sec_axis(sec.axis)
if (!is.sec_axis(sec.axis)) stop("Secondary axes must be specified using 'sec_axis()'")
sc$secondary.axis <- sec.axis
}
sc
}
#' @rdname scale_x_percent
#' @export
scale_y_comma <- function(name = waiver(),
breaks = waiver(),
minor_breaks = waiver(),
guide = waiver(),
n.breaks = NULL,
labels,
limits = NULL,
expand = c(0.01,0),
oob = censor,
na.value = NA_real_,
trans = "identity",
position = "left",
sec.axis = waiver(),
accuracy = 1,
scale = 1,
prefix = "",
suffix = "",
big.mark = ",",
decimal.mark = ".",
trim = TRUE,
...) {
if (missing(labels)) {
scales::comma_format(
accuracy = accuracy,
scale = scale,
prefix = prefix,
suffix = suffix,
big.mark = big.mark,
decimal.mark = decimal.mark,
trim = trim,
...
) -> labels
}
ggplot2::continuous_scale(
aesthetics = c(
"y", "ymin", "ymax", "yend", "yintercept",
"ymin_final", "ymax_final",
"lower", "middle", "upper"
),
scale_name = "position_c",
palette = identity,
name = name,
breaks = breaks,
n.breaks = n.breaks,
minor_breaks = minor_breaks,
labels = labels,
limits = limits,
expand = expand,
oob = oob,
na.value = na.value,
trans = trans,
guide = guide,
position = position,
super = ScaleContinuousPosition
) -> sc
if (!is.waive(sec.axis)) {
if (is.formula(sec.axis)) sec.axis <- ggplot2::sec_axis(sec.axis)
if (!is.sec_axis(sec.axis)) stop("Secondary axes must be specified using 'sec_axis()'")
sc$secondary.axis <- sec.axis
}
sc
}

+ 278
- 0
R/theme-gs.R View File

@ -0,0 +1,278 @@
#' ggplot2 Theme Based On The Goldman Sans Font Family
#'
#' Uses the built-in [gs_pkg] custom font.
#'
#' - `background_colour` dark mode is "`#121212`" else "`white`"
#' - `foreground_colour` dark mode is "`#e1e1e1`" else "`#262626`"
#' - `grid_col` dark mode is "`#606367`" else "`#cccccc`"
#' - `axis_col` dark mode is "`#606367`" else "`#2b2b2b`"
#'
#' @note this function updates `Geom` defaults; use [reset_ggplot2_defaults()] to
#' restore ggplot2 geom default aeshetics
#' @param base_size base font size
#' @param line_height default line height
#' @param plot_title_size plot title size
#' @param plot_title_position plot title position
#' @param plot_title_margin plot title margin
#' @param subtitle_size subtitle size
#' @param subtitle_margin subtitle margin
#' @param strip_text_size strip text size
#' @param strip_placement strip placement
#' @param caption_size caption size
#' @param caption_margin caption margin
#' @param axis_text_size axis text size
#' @param axis_title_size axis title size
#' @param axis_title_just axis title just
#' @param text_geom_size text geom size
#' @param panel_spacing panel spacing
#' @param plot_margin plot margin
#' @param grid_col grid col
#' @param grid grid
#' @param axis_col axis col
#' @param axis axis
#' @param ticks ticks
#' @return ggplot2 theme
#' @export
#' @examples
#' ggplot() +
#' geom_point(
#' data = mtcars,
#' aes(mpg, wt)
#' ) +
#' geom_label(
#' aes(
#' x = 30, y = 4.5,
#' label = "A fairly useless\nannotation that\nuses the custom\nInter variant\nby default."
#' ),
#' label.size = 0
#' ) +
#' labs(
#' x = "Fuel efficiency (mpg)", y = "Weight (tons)",
#' title = "Seminal ggplot2 scatterplot example",
#' subtitle = "A plot that is only useful for demonstration purposes",
#' caption = "Brought to you by the letter 'g'"
#' ) +
#' theme_gs(grid = "XY")
theme_gs <- function(
base_size = 11.5,
line_height = 0.875,
plot_title_size = 18,
plot_title_position = "panel",
plot_title_margin = 10,
subtitle_size = 12,
subtitle_margin = 12,
strip_text_size = 12,
strip_placement = "outer",
caption_size = 10,
caption_margin = 10,
axis_text_size = base_size,
axis_title_size = 10,
axis_title_just = "rt",
panel_spacing = grid::unit(2, "lines"),
plot_margin = margin(30, 30, 30, 30),
mode = c("light", "dark", "rstudio"),
background_colour = theme_background_color(mode, light = "white", dark = "#121212"),
foreground_colour = theme_foreground_color(mode, light = "#262626", dark = "#e1e1e1"),
grid_col = theme_foreground_color(mode, light = "#cccccc", dark = "#606367"),
axis_col = theme_foreground_color(mode, light = "#2b2b2b", dark = "#606367"),
grid = TRUE,
axis = FALSE,
ticks = FALSE) {
base_family <- gsc_pkg$normal
plot_title_family <- gs_pkg$bold
subtitle_family <- gs_pkg$normal
strip_text_family <- gsc_pkg$bold
axis_text_family <- gsc_pkg$normal
caption_family <- gsc_pkg$normal
axis_title_family <- gs_pkg$medium
c(
"GeomRect", "GeomLabel", "GeomTile", "GeomViolin"
) -> has_reverse_cols
geoms <- ls(pattern = '^Geom', env = as.environment('package:ggplot2'))
for (geom in geoms) {
update_geom_defaults(
geom = get(geom),
new = list(
arrow.fill = background_colour,
outlier.colour = foreground_colour,
outlier.fill = background_colour,
colour = foreground_colour,
fill = if (geom %in% c(has_reverse_cols)) background_colour else NA,
family = base_family,
lineheight = line_height
)
)
}
theme_minimal(
base_family = base_family,
base_size = base_size,
) +
theme(
rect = element_rect(colour = foreground_colour, fill = background_colour),
line = element_line(colour = foreground_colour),
title = element_text(colour = foreground_colour),
legend.background = element_blank(),
legend.key = element_blank(),
legend.text = element_text(colour = foreground_colour, family = inter_pkg$medium),
legend.title = element_text(colour = foreground_colour, family = inter_pkg$semibold)
) -> ret
if (inherits(grid, "character") | grid == TRUE) {
ret +
theme(
panel.grid = element_line(colour = grid_col, size = 0.2),
panel.grid.major = element_line(colour = grid_col, size = 0.2),
panel.grid.minor = element_line(colour = grid_col, size = 0.15)
) -> ret
if (inherits(grid, "character")) {
if (regexpr("X", grid)[1] < 0) ret <- ret + theme(panel.grid.major.x = element_blank())
if (regexpr("Y", grid)[1] < 0) ret <- ret + theme(panel.grid.major.y = element_blank())
if (regexpr("x", grid)[1] < 0) ret <- ret + theme(panel.grid.minor.x = element_blank())
if (regexpr("y", grid)[1] < 0) ret <- ret + theme(panel.grid.minor.y = element_blank())
}
} else {
ret <- ret + theme(panel.grid = element_blank())
}
if (inherits(axis, "character") | axis == TRUE) {
ret <- ret + theme(axis.line = element_line(colour = axis_col, size = 0.15))
if (inherits(axis, "character")) {
axis <- tolower(axis)
if (regexpr("x", axis)[1] < 0) {
ret <- ret + theme(axis.line.x = element_blank())
} else {
ret <- ret + theme(axis.line.x = element_line(colour = axis_col, size = 0.15))
}
if (regexpr("y", axis)[1] < 0) {
ret <- ret + theme(axis.line.y = element_blank())
} else {
ret <- ret + theme(axis.line.y = element_line(colour = axis_col, size = 0.15))
}
} else {
ret + theme(
axis.line.x = element_line(colour = axis_col, size = 0.15),
axis.line.y = element_line(colour = axis_col, size = 0.15)
) -> ret
}
} else {
ret <- ret + theme(axis.line = element_blank())
}
if (!ticks) {
ret + theme(
axis.ticks = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank()
) -> ret
} else {
ret + theme(
axis.ticks = element_line(size = 0.15),
axis.ticks.x = element_line(size = 0.15),
axis.ticks.y = element_line(size = 0.15),
axis.ticks.length = grid::unit(5, "pt")
) -> ret
}
xj <- switch(tolower(substr(axis_title_just, 1, 1)), b = 0, l = 0, m = 0.5, c = 0.5, r = 1, t = 1)
yj <- switch(tolower(substr(axis_title_just, 2, 2)), b = 0, l = 0, m = 0.5, c = 0.5, r = 1, t = 1)
ret +
theme(
axis.text.x = element_text(size = axis_text_size, margin = margin(t = 0), lineheight = line_height),
axis.text.x.top = element_text(size = axis_text_size, margin = margin(t = 0), lineheight = line_height),
axis.text.x.bottom = element_text(size = axis_text_size, margin = margin(t = 0), lineheight = line_height),
axis.text.y = element_text(size = axis_text_size, margin = margin(r = 0), lineheight = line_height),
axis.text.y.left = element_text(size = axis_text_size, margin = margin(r = 0), lineheight = line_height),
axis.text.y.right = element_text(size = axis_text_size, margin = margin(r = 0), lineheight = line_height),
axis.title = element_text(
size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.x = element_text(
hjust = xj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.x.top = element_text(
hjust = xj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.x.bottom = element_text(
hjust = xj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.y = element_text(
hjust = yj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.y.left = element_text(
hjust = yj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.y.right = element_text(
hjust = yj, size = axis_title_size, angle = 90,
family = axis_title_family, lineheight = line_height
),
strip.placement = strip_placement,
strip.text = element_text(
hjust = 0, size = strip_text_size, color = foreground_colour,
family = strip_text_family, lineheight = line_height
),
strip.text.x = element_text(
hjust = 0, size = strip_text_size, color = foreground_colour,
family = strip_text_family, lineheight = line_height
),
strip.background = element_rect(
fill = background_colour, color = NA
),
strip.background.x = element_rect(
fill = background_colour, color = NA
),
strip.background.y = element_rect(
fill = background_colour, color = NA
),
strip.text.y = element_text(
hjust = 0, size = strip_text_size, color = foreground_colour,
family = strip_text_family, lineheight = line_height
),
panel.spacing = panel_spacing,
panel.background = element_rect(color = NA, fill = background_colour),
plot.background = element_rect(color = NA, fill = background_colour),
plot.title.position = plot_title_position,
plot.margin = plot_margin,
plot.title = element_text(
hjust = 0, size = plot_title_size, margin = margin(b = plot_title_margin),
family = plot_title_family, lineheight = line_height
),
plot.subtitle = element_text(
hjust = 0, size = subtitle_size, margin = margin(b = subtitle_margin),
family = subtitle_family, lineheight = line_height
),
plot.caption = element_text(
hjust = 1, size = caption_size, margin = margin(t = caption_margin),
family = caption_family, lineheight = line_height
),
) -> ret
ret
}

+ 2
- 1
R/theme-inter.R View File

@ -7,7 +7,8 @@
#' - `grid_col` dark mode is "`#606367`" else "`#cccccc`"
#' - `axis_col` dark mode is "`#606367`" else "`#2b2b2b`"
#'
#' @note this function updates `Geom` defaults
#' @note this function updates `Geom` defaults; use [reset_ggplot2_defaults()] to
#' restore ggplot2 geom default aeshetics
#' @param base_size base font size
#' @param line_height default line height
#' @param plot_title_size plot title size


+ 278
- 0
R/theme-rc.R View File

@ -0,0 +1,278 @@
#' ggplot2 Theme Based On The Roboto Condensed Font Family
#'
#' Uses the built-in [rc_pkg] custom font.
#'
#' - `background_colour` dark mode is "`#121212`" else "`white`"
#' - `foreground_colour` dark mode is "`#e1e1e1`" else "`#262626`"
#' - `grid_col` dark mode is "`#606367`" else "`#cccccc`"
#' - `axis_col` dark mode is "`#606367`" else "`#2b2b2b`"
#'
#' @note this function updates `Geom` defaults; use [reset_ggplot2_defaults()] to
#' restore ggplot2 geom default aeshetics
#' @param base_size base font size
#' @param line_height default line height
#' @param plot_title_size plot title size
#' @param plot_title_position plot title position
#' @param plot_title_margin plot title margin
#' @param subtitle_size subtitle size
#' @param subtitle_margin subtitle margin
#' @param strip_text_size strip text size
#' @param strip_placement strip placement
#' @param caption_size caption size
#' @param caption_margin caption margin
#' @param axis_text_size axis text size
#' @param axis_title_size axis title size
#' @param axis_title_just axis title just
#' @param text_geom_size text geom size
#' @param panel_spacing panel spacing
#' @param plot_margin plot margin
#' @param grid_col grid col
#' @param grid grid
#' @param axis_col axis col
#' @param axis axis
#' @param ticks ticks
#' @return ggplot2 theme
#' @export
#' @examples
#' ggplot() +
#' geom_point(
#' data = mtcars,
#' aes(mpg, wt)
#' ) +
#' geom_label(
#' aes(
#' x = 30, y = 4.5,
#' label = "A fairly useless\nannotation that\nuses the custom\nInter variant\nby default."
#' ),
#' label.size = 0
#' ) +
#' labs(
#' x = "Fuel efficiency (mpg)", y = "Weight (tons)",
#' title = "Seminal ggplot2 scatterplot example",
#' subtitle = "A plot that is only useful for demonstration purposes",
#' caption = "Brought to you by the letter 'g'"
#' ) +
#' theme_rc(grid = "XY")
theme_rc <- function(
base_size = 10,
line_height = 0.875,
plot_title_size = 18,
plot_title_position = "panel",
plot_title_margin = 10,
subtitle_size = 12,
subtitle_margin = 12,
strip_text_size = 12,
strip_placement = "outer",
caption_size = 9,
caption_margin = 10,
axis_text_size = base_size,
axis_title_size = 9,
axis_title_just = "rt",
panel_spacing = grid::unit(2, "lines"),
plot_margin = margin(30, 30, 30, 30),
mode = c("light", "dark", "rstudio"),
background_colour = theme_background_color(mode, light = "white", dark = "#121212"),
foreground_colour = theme_foreground_color(mode, light = "#262626", dark = "#e1e1e1"),
grid_col = theme_foreground_color(mode, light = "#cccccc", dark = "#606367"),
axis_col = theme_foreground_color(mode, light = "#2b2b2b", dark = "#606367"),
grid = TRUE,
axis = FALSE,
ticks = FALSE) {
base_family <- rc_pkg$normal
plot_title_family <- rc_pkg$bold
subtitle_family <- rc_pkg$normal
strip_text_family <- rc_pkg$bold
axis_text_family <- rc_pkg$normal
caption_family <- rc_pkg$normal_light
axis_title_family <- rc_pkg$bold
c(
"GeomRect", "GeomLabel", "GeomTile", "GeomViolin"
) -> has_reverse_cols
geoms <- ls(pattern = '^Geom', env = as.environment('package:ggplot2'))
for (geom in geoms) {
update_geom_defaults(
geom = get(geom),
new = list(
arrow.fill = background_colour,
outlier.colour = foreground_colour,
outlier.fill = background_colour,
colour = foreground_colour,
fill = if (geom %in% c(has_reverse_cols)) background_colour else NA,
family = base_family,
lineheight = line_height
)
)
}
theme_minimal(
base_family = base_family,
base_size = base_size,
) +
theme(
rect = element_rect(colour = foreground_colour, fill = background_colour),
line = element_line(colour = foreground_colour),
title = element_text(colour = foreground_colour),
legend.background = element_blank(),
legend.key = element_blank(),
legend.text = element_text(colour = foreground_colour, family = inter_pkg$medium),
legend.title = element_text(colour = foreground_colour, family = inter_pkg$semibold)
) -> ret
if (inherits(grid, "character") | grid == TRUE) {
ret +
theme(
panel.grid = element_line(colour = grid_col, size = 0.2),
panel.grid.major = element_line(colour = grid_col, size = 0.2),
panel.grid.minor = element_line(colour = grid_col, size = 0.15)
) -> ret
if (inherits(grid, "character")) {
if (regexpr("X", grid)[1] < 0) ret <- ret + theme(panel.grid.major.x = element_blank())
if (regexpr("Y", grid)[1] < 0) ret <- ret + theme(panel.grid.major.y = element_blank())
if (regexpr("x", grid)[1] < 0) ret <- ret + theme(panel.grid.minor.x = element_blank())
if (regexpr("y", grid)[1] < 0) ret <- ret + theme(panel.grid.minor.y = element_blank())
}
} else {
ret <- ret + theme(panel.grid = element_blank())
}
if (inherits(axis, "character") | axis == TRUE) {
ret <- ret + theme(axis.line = element_line(colour = axis_col, size = 0.15))
if (inherits(axis, "character")) {
axis <- tolower(axis)
if (regexpr("x", axis)[1] < 0) {
ret <- ret + theme(axis.line.x = element_blank())
} else {
ret <- ret + theme(axis.line.x = element_line(colour = axis_col, size = 0.15))
}
if (regexpr("y", axis)[1] < 0) {
ret <- ret + theme(axis.line.y = element_blank())
} else {
ret <- ret + theme(axis.line.y = element_line(colour = axis_col, size = 0.15))
}
} else {
ret + theme(
axis.line.x = element_line(colour = axis_col, size = 0.15),
axis.line.y = element_line(colour = axis_col, size = 0.15)
) -> ret
}
} else {
ret <- ret + theme(axis.line = element_blank())
}
if (!ticks) {
ret + theme(
axis.ticks = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank()
) -> ret
} else {
ret + theme(
axis.ticks = element_line(size = 0.15),
axis.ticks.x = element_line(size = 0.15),
axis.ticks.y = element_line(size = 0.15),
axis.ticks.length = grid::unit(5, "pt")
) -> ret
}
xj <- switch(tolower(substr(axis_title_just, 1, 1)), b = 0, l = 0, m = 0.5, c = 0.5, r = 1, t = 1)
yj <- switch(tolower(substr(axis_title_just, 2, 2)), b = 0, l = 0, m = 0.5, c = 0.5, r = 1, t = 1)
ret +
theme(
axis.text.x = element_text(size = axis_text_size, margin = margin(t = 0), lineheight = line_height),
axis.text.x.top = element_text(size = axis_text_size, margin = margin(t = 0), lineheight = line_height),
axis.text.x.bottom = element_text(size = axis_text_size, margin = margin(t = 0), lineheight = line_height),
axis.text.y = element_text(size = axis_text_size, margin = margin(r = 0), lineheight = line_height),
axis.text.y.left = element_text(size = axis_text_size, margin = margin(r = 0), lineheight = line_height),
axis.text.y.right = element_text(size = axis_text_size, margin = margin(r = 0), lineheight = line_height),
axis.title = element_text(
size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.x = element_text(
hjust = xj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.x.top = element_text(
hjust = xj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.x.bottom = element_text(
hjust = xj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.y = element_text(
hjust = yj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.y.left = element_text(
hjust = yj, size = axis_title_size,
family = axis_title_family, lineheight = line_height
),
axis.title.y.right = element_text(
hjust = yj, size = axis_title_size, angle = 90,
family = axis_title_family, lineheight = line_height
),
strip.placement = strip_placement,
strip.text = element_text(
hjust = 0, size = strip_text_size, color = foreground_colour,
family = strip_text_family, lineheight = line_height
),
strip.text.x = element_text(
hjust = 0, size = strip_text_size, color = foreground_colour,
family = strip_text_family, lineheight = line_height
),
strip.background = element_rect(
fill = background_colour, color = NA
),
strip.background.x = element_rect(
fill = background_colour, color = NA
),
strip.background.y = element_rect(
fill = background_colour, color = NA
),
strip.text.y = element_text(
hjust = 0, size = strip_text_size, color = foreground_colour,
family = strip_text_family, lineheight = line_height
),
panel.spacing = panel_spacing,
panel.background = element_rect(color = NA, fill = background_colour),
plot.background = element_rect(color = NA, fill = background_colour),
plot.title.position = plot_title_position,
plot.margin = plot_margin,
plot.title = element_text(
hjust = 0, size = plot_title_size, margin = margin(b = plot_title_margin),
family = plot_title_family, lineheight = line_height
),
plot.subtitle = element_text(
hjust = 0, size = subtitle_size, margin = margin(b = subtitle_margin),
family = subtitle_family, lineheight = line_height
),
plot.caption = element_text(
hjust = 1, size = caption_size, margin = margin(t = caption_margin),
family = caption_family, lineheight = line_height
),
) -> ret
ret
}

+ 11
- 0
R/utils-pipe.R View File

@ -0,0 +1,11 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
NULL

+ 110
- 0
R/x-font-reg.R View File

@ -0,0 +1,110 @@
#' Inter Font Variant
#'
#' On load hrbragg creates a custom Inter font family variant
#' and makes it available in the global environment.
#'
#' The reconfigured family variant has the following features:
#'
#' - `calt`: (_Contextual Alternates_): Applies a second substitution feature
#' based on a match of a character pattern within a context of surrounding patterns
#' - `case` (_Case Sensitive Forms_): Replace characters, especially punctuation, with forms better suited for all-capital text, cf. titl
#' - `dlig`/`ligatures` (_Discretionary Ligatures_): Ligatures to be applied at the user's discretion
#' - `kern` (_Kerning_): Fine horizontal positioning of one glyph to the next, based on the shapes of the glyphs
#' - `salt` (_Stylistic Alternates_): **DISABLED** — Either replaces with, or displays list of, stylistic alternatives for a character
#' - `ss01` (_Stylistic set 1: Alternate digits_): An alternate style of digits.
#' - `tnum` (_Tabular Figures_): Replaces numerals with glyphs of uniform width, often also lnum
#' - `zero` (_Slashed Zero_): **DISABLED** — Replaces 0 figure with slashed 0
#'
#' Inter online documentation has [specific descriptions and examples of these features](https://rsms.me/inter/#features).
#'
#' This object has the following names corresponding to individual,
#' customized font variants (ordered by font weight):
#'
#' - `ultralight`
#' - `ultralight_italic`
#' - `light`
#' - `light_italic`
#' - `normal_italic`
#' - `normal`
#' - `medium_italic`
#' - `medium`
#' - `semibold_italic`
#' - `semibold`
#' - `bold`
#' - `bold_italic`
#' - `ultrabold`
#' - `ultrabold_italic`
#' - `heavy`
#' - `heavy_italic`
#'
#' @docType data
#' @format A list
#' @export
inter_pkg <- NULL
#' Robot Condensed Font Variant
#'
#' On load hrbragg creates a custom Roboto Condensed font family variant
#' and makes it available in the global environment.
#'
#' The reconfigured family variant has the following features:
#'
#' - `ccmp` (_Glyph Composition/Decomposition_): Either calls a ligature replacement
#' on a sequence of characters or replaces a character with a sequence of glyphs.
#' Provides logic that can for example effectively alter the order of input characters.
#' - `liga`/`ligatures` (_Standard Ligatures_): Replaces (by default) sequence of characters with a single ligature glyph
#' - `kern` (_Kerning_): Fine horizontal positioning of one glyph to the next, based on the shapes of the glyphs
#' - `tnum` (_Tabular Figures_): Replaces numerals with glyphs of uniform width, often also lnum
#'
#' Roboto Condensed
#' [font family preview/info](https://fonts.google.com/specimen/Roboto+Condensed)
#'
#' This object has the following names corresponding to individual,
#' customized font variants (ordered by font weight):
#'
#' - `normal_light`
#' - `normal`
#' - `normal_italic`
#' - `bold`
#'
#' @docType data
#' @format A list
#' @export
rc_pkg <- NULL
#' Goldman Sans & Goldman Sans Condensed Font Variants
#'
#' On load hrbragg creates a custom Goldman Sans & Goldman Sans Condensed
#' font family variants and makes them available in the global environment.
#'
#' The reconfigured family variant has the following features:
#'
#' This object has the following names corresponding to individual,
#' customized font variants (ordered by font weight):
#'
#' **Goldman Sans** (`gs_rc`)
#'
#' - `light`
#' - `normal_italic`
#' - `normal_light`
#' - `medium`
#' - `medium_italic`
#' - `bold`
#' - `bold_italic`
#' - `heavy`
#'
#' **Goldman Sans Condensed** (`gsc_rc`)
#'
#' - `normal`
#' - `bold`
#'
#' @docType data
#' @format A list
#' @export
gs_pkg <- NULL
#' @docType data
#' @format A list
#' @export
gsc_pkg <- NULL

+ 66
- 48
R/zzz.R View File

@ -1,53 +1,7 @@
#' Inter Font Variant
#'
#' On load {hrbragg} creates a custom Inter font family variant
#' and makes it available in the global environment.
#'
#' The reconfigured family variant has the following features:
#'
#' - `calt`: (_Contextual Alternates_): Applies a second substitution feature
#' based on a match of a character pattern within a context of surrounding patterns
#' - `case` (_Case Sensitive Forms_): Replace characters, especially punctuation, with forms better suited for all-capital text, cf. titl
#' - `dlig`/`ligatures` (_Discretionary Ligatures_): Ligatures to be applied at the user's discretion
#' - `kern` (_Kerning_): Fine horizontal positioning of one glyph to the next, based on the shapes of the glyphs
#' - `salt` (_Stylistic Alternates_): **DISABLED** — Either replaces with, or displays list of, stylistic alternatives for a character
#' - `ss01` (_Stylistic set 1: Alternate digits_): An alternate style of digits.
#' - `tnum` (_Tabular Figures_): Replaces numerals with glyphs of uniform width, often also lnum
#' - `zero` (_Slashed Zero_): **DISABLED** — Replaces 0 figure with slashed 0
#'
#' Inter online documentation has [specific descriptions and exaples of these features](https://rsms.me/inter/#features).
#'
#' This object has the following names corresponding to individual,
#' customized font variants (ordered by font weight):
#'
#' - `ultralight`
#' - `ultralight_italic`
#' - `light`
#' - `light_italic`
#' - `normal_italic`
#' - `normal`
#' - `medium_italic`
#' - `medium`
#' - `semibold_italic`
#' - `semibold`
#' - `bold`
#' - `bold_italic`
#' - `ultrabold`
#' - `ultrabold_italic`
#' - `heavy`
#' - `heavy_italic`
#'
#' @docType data
#' @format A list
#' @export
inter_pkg <- NULL
.onLoad <- function(...) {