Browse Source

more themes and helpers

master
boB Rudis 3 years ago
parent
commit
1eaf024f45
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 3
      DESCRIPTION
  2. 15
      NAMESPACE
  3. 56
      R/install-fonts.R
  4. 62
      R/preview-variant.R
  5. 3
      R/reconfigure-font.R
  6. 95
      R/reset-ggplot2-defaults.R
  7. 278
      R/roboto-condensed.R
  8. 339
      R/scales.R
  9. 278
      R/theme-gs.R
  10. 3
      R/theme-inter.R
  11. 278
      R/theme-rc.R
  12. 11
      R/utils-pipe.R
  13. 110
      R/x-font-reg.R
  14. 114
      R/zzz.R
  15. 62
      README.Rmd
  16. 135
      README.md
  17. 2574
      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
      man/gs_pkg.Rd
  32. 23
      man/install_goldman_sans.Rd
  33. 22
      man/install_roboto_condensed.Rd
  34. 6
      man/inter_pkg.Rd
  35. 12
      man/pipe.Rd
  36. 51
      man/preview_variant.Rd
  37. 40
      man/rc_pkg.Rd
  38. 11
      man/reset_ggplot2_defaults.Rd
  39. 172
      man/scale_x_percent.Rd
  40. 117
      man/theme_gs.Rd
  41. 3
      man/theme_inter.Rd
  42. 117
      man/theme_rc.Rd

3
DESCRIPTION

@ -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
NAMESPACE

@ -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)

56
R/install-fonts.R

@ -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
R/preview-variant.R

@ -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()
)
}

3
R/reconfigure-font.R

@ -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
R/reset-ggplot2-defaults.R

@ -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]]
)
}
}

278
R/roboto-condensed.R

@ -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
R/scales.R

@ -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
R/theme-gs.R

@ -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
}

3
R/theme-inter.R

@ -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
R/theme-rc.R

@ -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
R/utils-pipe.R

@ -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
R/x-font-reg.R

@ -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

114
R/zzz.R

@ -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(...) {
if (systemfonts::font_info("Inter")[["family"]][1] == "Inter") {
if (interactive()) packageStartupMessage("Registering 'Inter' font variant.")
reconfigure_font(
prefix = "hrbragg-pkg",
family = "Inter",
@ -57,13 +11,77 @@ inter_pkg <- NULL
dlig = 1, ss01 = 1, kern = 1,
zero = 0, salt = 0
) ->> inter_pkg
} else {
packageStartupMessage(
"Please run `install_inter()`. This is only an interim requirement."
)
}
if (systemfonts::font_info("Roboto Condensed")[["family"]][1] == "Roboto Condensed") {
reconfigure_font(
prefix = "hrbragg",
family = "Roboto Condensed",
width = "normal",
ligatures = "standard",
ccmp = 1, kern = 1, tnum = 1
) ->> rc_pkg
} else {
packageStartupMessage(
"Please run `install_roboto_condensed()`. This is only an interim requirement."
)
}
if (systemfonts::font_info("Goldman Sans")[["family"]][1] == "Goldman Sans") {
reconfigure_font(
prefix = "hrbragg",
family = "Goldman Sans",
width = "normal",
ligatures = "standard",
kern = 1, tnum = 1
) ->> gs_pkg
reconfigure_font(
prefix = "hrbragg",
family = "Goldman Sans Condensed",
width = "semicondensed",
ligatures = "standard",
kern = 1, tnum = 1
) ->> gsc_pkg
} else {
packageStartupMessage(
"Please run `install_goldman_sans()`. This is only an interim requirement."
)
}
}

62
README.Rmd

@ -38,6 +38,7 @@ hrbrpkghelpr::install_block()
## Usage
```{r lib-ex}
library(tibble)
library(hrbragg)
library(ggplot2)
@ -52,10 +53,18 @@ For the moment, you'll need to install Inter:
install_inter()
```
### Inspect the definitions of the feature codes:
```{r ex-00}
str(inter_pkg, 1)
data("feature_dict")
feature_dict[feature_dict$tag %in% textshaping::get_font_features("Inter")[[1]],]
```
### Let's make a plot!
```{r ex-01}
ggplot() +
geom_point(
@ -77,15 +86,38 @@ ggplot() +
) -> gg1
```
### Dark & light mode support with just a parameter change!
```{r dark-mode-01}
gg1 + theme_inter(grid = "XY", mode = "dark")
```
Note the ligatures aren't as nice in Goldman Sans
```{r dark-mode-01-rc}
gg1 + theme_rc(grid = "XY", mode = "dark")
```
### Note the ligatures aren't as nice in or Roboto Condensed
```{r dark-mode-01-gs}
gg1 + theme_gs(grid = "XY", mode = "dark")
```
```{r light-mode-01}
gg1 + theme_inter(grid = "XY", mode = "light")
```
```{r light-mode-01-rc}
gg1 + theme_rc(grid = "XY", mode = "light")
```
```{r light-mode-01-gs}
gg1 + theme_gs(grid = "XY", mode = "light")
```
### Making sure we got all the various plot components styled
```{r ex-02}
ggplot() +
geom_point(
@ -111,6 +143,36 @@ gg2 + theme_inter(grid = "XY", mode = "light")
gg2 + theme_inter(grid = "XY", mode = "dark")
```
### Here's a way to preview any variants you create:
```{r preview-00, fig.width=600/96, fig.height=1300/96}
preview_variant(inter_pkg)
```
```{r preview-01, fig.width=400/96, fig.height=300/96}
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)
```
```{r preview-02, fig.width=600/96, fig.height=1100/96}
reconfigure_font(
family = "Barlow",
width = "normal",
ligatures = "standard",
tnum = 1, kern = 1
) -> barlow
preview_variant(barlow)
```
## hrbragg Metrics
```{r cloc, echo=FALSE}

135
README.md

@ -35,12 +35,24 @@ The following functions are implemented:
- `elr`: Shortcut for element\_rect
- `elt`: Shortcut for element\_text
- `feature_dict`: OpenType feature description lookup table
- `gs_pkg`: Goldman Sans & Goldman Sans Condensed Font Variants
- `install_goldman_sans`: Install Goldman Sans (Condensed)
- `install_inter`: Install Inter
- `install_roboto_condensed`: Install Roboto Condensed
- `inter_pkg`: Inter Font Variant
- `opentype_typographic_features`: OpenType Typographic Features
- `preview_variant`: Preview numbers, kerning, and ligatures from font
variants you create
- `rc_pkg`: Robot Condensed Font Variant
- `reconfigure_font`: Create an complete, alternate font family with
the same customized features
- `reset_ggplot2_defaults`: Restore all ggplot2 geom to default
aesthetics
- `scale_x_percent`: X & Y scales with opinionated pre-sets for
percent & comma label formats
- `theme_gs`: ggplot2 Theme Based On The Goldman Sans Font Family
- `theme_inter`: ggplot2 Theme Based On The Inter Font Family
- `theme_rc`: ggplot2 Theme Based On The Roboto Condensed Font Family
## Installation
@ -50,6 +62,8 @@ remotes::install_git("https://git.rud.is/hrbrmstr/hrbragg.git")
remotes::install_gitlab("hrbrmstr/hrbragg")
# or
remotes::install_bitbucket("hrbrmstr/hrbragg")
# or
remotes::install_github("hrbrmstr/hrbragg")
```
NOTE: To use the ‘remotes’ install options you will need to have the
@ -58,6 +72,7 @@ NOTE: To use the ‘remotes’ install options you will need to have the
## Usage
``` r
library(tibble)
library(hrbragg)
library(ggplot2)
@ -72,28 +87,59 @@ For the moment, you’ll need to install Inter:
install_inter()
```
### Inspect the definitions of the feature codes:
``` r
str(inter_pkg, 1)
## List of 16
## $ ultralight : chr "hrbragg-pkg Inter Thin"
## List of 17
## $ ultralight_italic: chr "hrbragg-pkg Inter Thin Italic"
## $ ultralight : chr "hrbragg-pkg Inter Thin"
## $ light : chr "hrbragg-pkg Inter Extra Light"
## $ light_italic : chr "hrbragg-pkg Inter Extra Light Italic"
## $ normal_italic : chr "hrbragg-pkg Inter Light Italic"
## $ normal : chr "hrbragg-pkg Inter Light"
## $ normal_light : chr "hrbragg-pkg Inter Light"
## $ normal : chr "hrbragg-pkg Inter Regular"
## $ medium_italic : chr "hrbragg-pkg Inter Medium Italic"
## $ medium : chr "hrbragg-pkg Inter Medium"
## $ semibold_italic : chr "hrbragg-pkg Inter Semi Bold Italic"
## $ semibold : chr "hrbragg-pkg Inter Semi Bold"
## $ semibold_italic : chr "hrbragg-pkg Inter Semi Bold Italic"
## $ bold : chr "hrbragg-pkg Inter Bold"
## $ bold_italic : chr "hrbragg-pkg Inter Bold Italic"
## $ ultrabold : chr "hrbragg-pkg Inter Extra Bold"
## $ ultrabold_italic : chr "hrbragg-pkg Inter Extra Bold Italic"
## $ heavy : chr "hrbragg-pkg Inter Black"
## $ ultrabold : chr "hrbragg-pkg Inter Extra Bold"
## $ heavy_italic : chr "hrbragg-pkg Inter Black Italic"
## $ heavy : chr "hrbragg-pkg Inter Black"
## - attr(*, "family")= chr "Inter"
data("feature_dict")
feature_dict[feature_dict$tag %in% textshaping::get_font_features("Inter")[[1]],]
## # A tibble: 19 x 3
## tag long_name description
## <chr> <chr> <chr>
## 1 aalt Access All Alternates Special feature: used to present user with choice all alternate forms of the charact…
## 2 calt Contextual Alternates Applies a second substitution feature based on a match of a character pattern within…
## 3 case Case Sensitive Forms Replace characters, especially punctuation, with forms better suited for all-capital…
## 4 ccmp Glyph Composition/Decomp… Either calls a ligature replacement on a sequence of characters or replaces a charac…
## 5 cpsp Capital Spacing Adjusts spacing between letters in all-capitals text
## 6 dlig Discretionary Ligatures Ligatures to be applied at the user's discretion
## 7 dnom Denominator Converts to appropriate fraction denominator form, invoked by frac
## 8 frac Fractions Converts figures separated by slash with diagonal fraction
## 9 kern Kerning Fine horizontal positioning of one glyph to the next, based on the shapes of the gly…
## 10 locl Localized Forms Substitutes character with the preferred form based on script language
## 11 mark Mark Positioning Fine positioning of a mark glyph to a base character
## 12 numr Numerator Converts to appropriate fraction numerator form, invoked by frac
## 13 ordn Ordinals Replaces characters with ordinal forms for use after numbers
## 14 pnum Proportional Figures Replaces numerals with glyphs of proportional width, often also onum
## 15 salt Stylistic Alternates Either replaces with, or displays list of, stylistic alternatives for a character
## 16 subs Subscript Replaces character with subscript version, cf. numr
## 17 sups Superscript Replaces character with superscript version, cf. dnom
## 18 tnum Tabular Figures Replaces numerals with glyphs of uniform width, often also lnum
## 19 zero Slashed Zero Replaces 0 figure with slashed 0
```
### Let’s make a plot!
``` r
ggplot() +
geom_point(
@ -115,12 +161,30 @@ ggplot() +
) -> gg1
```
### Dark & light mode support with just a parameter change!
``` r
gg1 + theme_inter(grid = "XY", mode = "dark")
```
<img src="man/figures/README-dark-mode-01-1.png" width="672" />
Note the ligatures aren’t as nice in Goldman Sans
``` r
gg1 + theme_rc(grid = "XY", mode = "dark")
```
<img src="man/figures/README-dark-mode-01-rc-1.png" width="672" />
### Note the ligatures aren’t as nice in or Roboto Condensed
``` r
gg1 + theme_gs(grid = "XY", mode = "dark")
```
<img src="man/figures/README-dark-mode-01-gs-1.png" width="672" />
``` r
gg1 + theme_inter(grid = "XY", mode = "light")
```
@ -128,6 +192,20 @@ gg1 + theme_inter(grid = "XY", mode = "light")
<img src="man/figures/README-light-mode-01-1.png" width="672" />
``` r
gg1 + theme_rc(grid = "XY", mode = "light")
```
<img src="man/figures/README-light-mode-01-rc-1.png" width="672" />
``` r
gg1 + theme_gs(grid = "XY", mode = "light")
```
<img src="man/figures/README-light-mode-01-gs-1.png" width="672" />
### Making sure we got all the various plot components styled
``` r
ggplot() +
geom_point(
data = mpg,
@ -156,13 +234,50 @@ gg2 + theme_inter(grid = "XY", mode = "dark")
<img src="man/figures/README-dark-mode-02-1.png" width="1400" />
### Here’s a way to preview any variants you create:
``` r
preview_variant(inter_pkg)
```
<img src="man/figures/README-preview-00-1.png" width="600" />
``` r
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)
```
<img src="man/figures/README-preview-01-1.png" width="400" />
``` r
reconfigure_font(
family = "Barlow",
width = "normal",
ligatures = "standard",
tnum = 1, kern = 1
) -> barlow
preview_variant(barlow)
```
<img src="man/figures/README-preview-02-1.png" width="600" />
## hrbragg Metrics
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
|:-----|---------:|-----:|----:|-----:|------------:|-----:|---------:|-----:|
| R | 13 | 0.46 | 332 | 0.43 | 89 | 0.39 | 646 | 0.47 |
| Rmd | 1 | 0.04 | 50 | 0.07 | 26 | 0.11 | 46 | 0.03 |
| SUM | 14 | 0.50 | 382 | 0.50 | 115 | 0.50 | 692 | 0.50 |
|:-----|---------:|-----:|-----:|-----:|------------:|-----:|---------:|-----:|
| SVG | 1 | 0.02 | 2574 | 0.34 | 0 | 0.00 | 0 | 0.00 |
| R | 19 | 0.45 | 1131 | 0.15 | 215 | 0.42 | 642 | 0.45 |
| Rmd | 1 | 0.02 | 74 | 0.01 | 43 | 0.08 | 67 | 0.05 |
| SUM | 21 | 0.50 | 3779 | 0.50 | 258 | 0.50 | 709 | 0.50 |
clock Package Metrics for hrbragg

2574
Rplot.svg

File diff suppressed because it is too large

After

Width:  |  Height:  |  Size: 412 KiB

BIN
inst/fonts/goldman-sans-condensed/GoldmanSansCd_Bd.ttf

Binary file not shown.

BIN
inst/fonts/goldman-sans-condensed/GoldmanSansCd_Rg.ttf

Binary file not shown.

BIN
man/figures/README-dark-mode-01-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 62 KiB

BIN
man/figures/README-dark-mode-01-gs-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
man/figures/README-dark-mode-01-rc-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
man/figures/README-dark-mode-02-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 155 KiB

BIN
man/figures/README-light-mode-01-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 62 KiB

BIN
man/figures/README-light-mode-01-gs-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
man/figures/README-light-mode-01-rc-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
man/figures/README-light-mode-02-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 159 KiB

BIN
man/figures/README-preview-00-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

BIN
man/figures/README-preview-01-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
man/figures/README-preview-02-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

41
man/gs_pkg.Rd

@ -0,0 +1,41 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/x-font-reg.R
\docType{data}
\name{gs_pkg}
\alias{gs_pkg}
\title{Goldman Sans & Goldman Sans Condensed Font Variants}
\format{
A list
}
\usage{
gs_pkg
}
\description{
On load hrbragg creates a custom Goldman Sans & Goldman Sans Condensed
font family variants and makes them available in the global environment.
}
\details{
The reconfigured family variant has the following features:
This object has the following names corresponding to individual,
customized font variants (ordered by font weight):
\strong{Goldman Sans} (\code{gs_rc})
\itemize{
\item \code{light}
\item \code{normal_italic}
\item \code{normal_light}
\item \code{medium}
\item \code{medium_italic}
\item \code{bold}
\item \code{bold_italic}
\item \code{heavy}
}
\strong{Goldman Sans Condensed} (\code{gsc_rc})
\itemize{
\item \code{normal}
\item \code{bold}
}
}
\keyword{datasets}

23
man/install_goldman_sans.Rd

@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/install-fonts.R
\name{install_goldman_sans}
\alias{install_goldman_sans}
\title{Install Goldman Sans (Condensed)}
\usage{
install_goldman_sans()
}
\description{
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.
}
\note{
\href{https://design.gs.com/d/legal/goldman-sans-license}{Goldman Sans Restricted Font License}
}
\examples{
install_goldman_sans()
}
\references{
\href{https://design.gs.com/d/story/goldman-sans/}{Goldman Sans}
}

22
man/install_roboto_condensed.Rd

@ -0,0 +1,22 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/install-fonts.R
\name{install_roboto_condensed}
\alias{install_roboto_condensed}
\title{Install Roboto Condensed}
\usage{
install_roboto_condensed()
}
\description{
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{
\href{http://www.apache.org/licenses/LICENSE-2.0}{Apache License, Version 2.0.}
}
\examples{
install_roboto_condensed()
}

6
man/inter_pkg.Rd

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/zzz.R
% Please edit documentation in R/x-font-reg.R
\docType{data}
\name{inter_pkg}
\alias{inter_pkg}
@ -11,7 +11,7 @@ A list
inter_pkg
}
\description{
On load {hrbragg} creates a custom Inter font family variant
On load hrbragg creates a custom Inter font family variant
and makes it available in the global environment.
}
\details{
@ -28,7 +28,7 @@ based on a match of a character pattern within a context of surrounding patterns
\item \code{zero} (\emph{Slashed Zero}): \strong{DISABLED} — Replaces 0 figure with slashed 0
}
Inter online documentation has \href{https://rsms.me/inter/#features}{specific descriptions and exaples of these features}.
Inter online documentation has \href{https://rsms.me/inter/#features}{specific descriptions and examples of these features}.
This object has the following names corresponding to individual,
customized font variants (ordered by font weight):

12
man/pipe.Rd

@ -0,0 +1,12 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils-pipe.R
\name{\%>\%}
\alias{\%>\%}
\title{Pipe operator}
\usage{
lhs \%>\% rhs
}
\description{
See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
}
\keyword{internal}

51
man/preview_variant.Rd

@ -0,0 +1,51 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/preview-variant.R
\name{preview_variant}
\alias{preview_variant}
\title{Preview numbers, kerning, and ligatures from font variants you create}
\usage{
preview_variant(
font_variant,
font_size = 5,
test_label = "Lorem Ipsum dolor sit amet consectetur. => A\\u20dd\\n−0+1:2~3,456789\\n−9+8:7~6,543210"
)
}
\arguments{
\item{font_variant}{a font variant object created with \code{\link[=reconfigure_font]{reconfigure_font()}}}
\item{font_size}{passed to \code{\link[ggplot2:geom_text]{ggplot2::geom_text()}}}
\item{test_label}{a specially designed preview string to showcase some
specific font features}
}
\value{
A ggplot2 object
}
\description{
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 \code{test_label} if you wish to use a custom preview string.
}
\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)
}

40
man/rc_pkg.Rd

@ -0,0 +1,40 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/x-font-reg.R
\docType{data}
\name{rc_pkg}
\alias{rc_pkg}
\title{Robot Condensed Font Variant}
\format{
A list
}
\usage{
rc_pkg
}
\description{
On load hrbragg creates a custom Roboto Condensed font family variant
and makes it available in the global environment.
}
\details{
The reconfigured family variant has the following features:
\itemize{
\item \code{ccmp} (\emph{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.
\item \code{liga}/\code{ligatures} (\emph{Standard Ligatures}): Replaces (by default) sequence of characters with a single ligature glyph
\item \code{kern} (\emph{Kerning}): Fine horizontal positioning of one glyph to the next, based on the shapes of the glyphs
\item \code{tnum} (\emph{Tabular Figures}): Replaces numerals with glyphs of uniform width, often also lnum
}
Roboto Condensed
\href{https://fonts.google.com/specimen/Roboto+Condensed}{font family preview/info}
This object has the following names corresponding to individual,
customized font variants (ordered by font weight):
\itemize{
\item \code{normal_light}
\item \code{normal}
\item \code{normal_italic}
\item \code{bold}
}
}
\keyword{datasets}

11
man/reset_ggplot2_defaults.Rd

@ -0,0 +1,11 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reset-ggplot2-defaults.R
\name{reset_ggplot2_defaults}
\alias{reset_ggplot2_defaults}
\title{Restore all ggplot2 geom to default aesthetics}
\usage{
reset_ggplot2_defaults()
}
\description{
Restore all ggplot2 geom to default aesthetics
}

172
man/scale_x_percent.Rd

@ -0,0 +1,172 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scales.R
\name{scale_x_percent}
\alias{scale_x_percent}
\alias{scale_y_percent}
\alias{scale_x_comma}
\alias{scale_y_comma}
\title{X & Y scales with opinionated pre-sets for percent & comma label formats}
\usage{
scale_x_percent(
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,
...
)
scale_y_percent(
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,
...
)
scale_x_comma(
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,
...
)
scale_y_comma(
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,
...
)
}
\arguments{
\item{name}{The name of the scale. Used as axis or legend title. If
\code{waiver()}, the default, the name of the scale is taken from the first
mapping used for that aesthetic. If \code{NULL}, the legend title will be
omitted.}
\item{breaks}{One of:
\itemize{
\item \code{NULL} for no breaks
\item \code{waiver()} for the default breaks computed by the
transformation object
\item A numeric vector of positions
\item A function that takes the limits as input and returns breaks
as output
}}
\item{minor_breaks}{One of:
\itemize{
\item \code{NULL} for no minor breaks
\item \code{waiver()} for the default breaks (one minor break between
each major break)
\item A numeric vector of positions
\item A function that given the limits returns a vector of minor breaks.
}}
\item{guide}{guide A function used to create a guide or its name. See \code{\link[=guides]{guides()}} for more information.}
\item{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
\code{breaks = waiver()}. Use NULL to use the default number of breaks given by the transformation.}
\item{labels}{Specifying overrides the default format (i.e. you really don't
want to do that). \code{NULL} means no labels.}
\item{limits}{A numeric vector of length two providing limits of the scale.
Use \code{NA} to refer to the existing minimum or maximum.}
\item{expand}{same as in ggplot2}
\item{oob}{Function that handles limits outside of the scale limits
(out of bounds). The default replaces out of bounds values with NA.}
\item{na.value}{If \code{na.translate = TRUE}, what value aesthetic
value should missing be displayed as? Does not apply to position scales
where \code{NA} is always placed at the far right.}
\item{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".}
\item{position}{The position of the axis. "left" or "right" for vertical
scales, "top" or "bottom" for horizontal scales}
\item{sec.axis}{specify a secondary axis}
\item{accuracy, scale, prefix, suffix, big.mark, decimal.mark, trim}{See
\code{\link[scales:label_number]{scales::comma_format()}} or \code{\link[scales:label_percent]{scales::percent_format()}}}
\item{...}{passed on to \code{\link[scales:label_number]{scales::comma_format()}} or \code{\link[scales:label_percent]{scales::percent_format()}}}
}
\description{
The \verb{_comma} ones set comma format for axis text and \code{expand=c(0,0)} (you need to set limits).
}
\details{
The \verb{_percent} ones set precent format for axis text and \code{expand=c(0,0)} (you need to set limits).
}

117
man/theme_gs.Rd

@ -0,0 +1,117 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme-gs.R
\name{theme_gs}
\alias{theme_gs}
\title{ggplot2 Theme Based On The Goldman Sans Font Family}
\usage{
theme_gs(
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
)
}
\arguments{
\item{base_size}{base font size}
\item{line_height}{default line height}
\item{plot_title_size}{plot title size}
\item{plot_title_position}{plot title position}
\item{plot_title_margin}{plot title margin}
\item{subtitle_size}{subtitle size}
\item{subtitle_margin}{subtitle margin}
\item{strip_text_size}{strip text size}
\item{strip_placement}{strip placement}
\item{caption_size}{caption size}
\item{caption_margin}{caption margin}
\item{axis_text_size}{axis text size}
\item{axis_title_size}{axis title size}
\item{axis_title_just}{axis title just}
\item{panel_spacing}{panel spacing}
\item{plot_margin}{plot margin}
\item{grid_col}{grid col}
\item{axis_col}{axis col}
\item{grid}{grid}
\item{axis}{axis}
\item{ticks}{ticks}
\item{text_geom_size}{text geom size}
}
\value{
ggplot2 theme
}
\description{
Uses the built-in \link{gs_pkg} custom font.
}
\details{
\itemize{
\item \code{background_colour} dark mode is "\verb{#121212}" else "\code{white}"
\item \code{foreground_colour} dark mode is "\verb{#e1e1e1}" else "\verb{#262626}"
\item \code{grid_col} dark mode is "\verb{#606367}" else "\verb{#cccccc}"
\item \code{axis_col} dark mode is "\verb{#606367}" else "\verb{#2b2b2b}"
}
}
\note{
this function updates \code{Geom} defaults; use \code{\link[=reset_ggplot2_defaults]{reset_ggplot2_defaults()}} to
restore ggplot2 geom default aeshetics
}
\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")
}

3
man/theme_inter.Rd

@ -91,7 +91,8 @@ Uses the built-in \link{inter_pkg} custom font.
}
}
\note{
this function updates \code{Geom} defaults
this function updates \code{Geom} defaults; use \code{\link[=reset_ggplot2_defaults]{reset_ggplot2_defaults()}} to
restore ggplot2 geom default aeshetics
}
\examples{
ggplot() +

117
man/theme_rc.Rd

@ -0,0 +1,117 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/theme-rc.R
\name{theme_rc}
\alias{theme_rc}
\title{ggplot2 Theme Based On The Roboto Condensed Font Family}
\usage{
theme_rc(
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
)
}
\arguments{
\item{base_size}{base font size}
\item{line_height}{default line height}
\item{plot_title_size}{plot title size}
\item{plot_title_position}{plot title position}
\item{plot_title_margin}{plot title margin}
\item{subtitle_size}{subtitle size}
\item{subtitle_margin}{subtitle margin}
\item{strip_text_size}{strip text size}
\item{strip_placement}{strip placement}
\item{caption_size}{caption size}
\item{caption_margin}{caption margin}
\item{axis_text_size}{axis text size}
\item{axis_title_size}{axis title size}
\item{axis_title_just}{axis title just}
\item{panel_spacing}{panel spacing}
\item{plot_margin}{plot margin}
\item{grid_col}{grid col}
\item{axis_col}{axis col}
\item{grid}{grid}
\item{axis}{axis}
\item{ticks}{ticks}
\item{text_geom_size}{text geom size}
}
\value{
ggplot2 theme
}
\description{
Uses the built-in \link{rc_pkg} custom font.
}
\details{
\itemize{
\item \code{background_colour} dark mode is "\verb{#121212}" else "\code{white}"
\item \code{foreground_colour} dark mode is "\verb{#e1e1e1}" else "\verb{#262626}"
\item \code{grid_col} dark mode is "\verb{#606367}" else "\verb{#cccccc}"
\item \code{axis_col} dark mode is "\verb{#606367}" else "\verb{#2b2b2b}"
}
}
\note{
this function updates \code{Geom} defaults; use \code{\link[=reset_ggplot2_defaults]{reset_ggplot2_defaults()}} to
restore ggplot2 geom default aeshetics
}
\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")
}
Loading…
Cancel
Save