项目作者: hrbrmstr

项目描述 :
Typography-centric Themes, Theme Components, and Utilities for 'ggplot2' and 'ragg'.
高级语言: R
项目地址: git://github.com/hrbrmstr/hrbragg.git
创建时间: 2021-02-16T06:09:01Z
项目社区:https://github.com/hrbrmstr/hrbragg

开源协议:Other

下载


Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.
Signed
by
Signed commit
%
Linux build
Status
Coverage
Status
Minimal R
Version
License

hrbragg

Typography-centric Themes, Theme Components, and Utilities for ‘ggplot2’
and ‘ragg’.

Description

The ‘ragg’, ‘systemfonts’, and ‘textshaping’ packages make it possible
to create plot components and themes that make full use of the rich
typography features in modern fonts. Fonts, themes, and utilities are
provided to create ‘ggplot2’ plots intended for rendering on ‘ragg’
graphics devices.

What’s Inside The Tin

The following functions are implemented:

  • adaptive_color: Adaptive colors colors for hrbragg themes
  • elb: Shortcut for element_blank
  • ell: Shortcut for element_line
  • 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
  • install_inter: Install Inter
  • install_roboto_condensed: Install Roboto Condensed
  • inter_pkg: Inter Font Variants
  • opentype_typographic_features: OpenType Typographic Features
  • preview_variant: Preview numbers, kerning, and ligatures from font
    variants you create
  • rc_pkg: Roboto Condensed Font Variants
  • 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

  1. remotes::install_git("https://git.rud.is/hrbrmstr/hrbragg.git")
  2. # or
  3. remotes::install_gitlab("hrbrmstr/hrbragg")
  4. # or
  5. remotes::install_bitbucket("hrbrmstr/hrbragg")
  6. # or
  7. remotes::install_github("hrbrmstr/hrbragg")

NOTE: To use the ‘remotes’ install options you will need to have the
{remotes} package installed.

Usage

  1. library(tibble)
  2. library(hrbragg)
  3. library(ggplot2)
  4. # current version
  5. packageVersion("hrbragg")
  6. ## [1] '0.1.0'

For the moment, you’ll need to install Inter:

  1. install_inter()

Inspect the definitions of the feature codes:

  1. str(inter_pkg, 1)
  2. ## List of 17
  3. ## $ ultralight : chr "hrbragg-pkg tab Inter Thin"
  4. ## $ ultralight_italic: chr "hrbragg-pkg tab Inter Thin Italic"
  5. ## $ light : chr "hrbragg-pkg tab Inter Extra Light"
  6. ## $ light_italic : chr "hrbragg-pkg tab Inter Extra Light Italic"
  7. ## $ normal_italic : chr "hrbragg-pkg tab Inter Light Italic"
  8. ## $ normal : chr "hrbragg-pkg tab Inter Regular"
  9. ## $ normal_light : chr "hrbragg-pkg tab Inter Light"
  10. ## $ medium_italic : chr "hrbragg-pkg tab Inter Medium Italic"
  11. ## $ medium : chr "hrbragg-pkg tab Inter Medium"
  12. ## $ semibold_italic : chr "hrbragg-pkg tab Inter Semi Bold Italic"
  13. ## $ semibold : chr "hrbragg-pkg tab Inter Semi Bold"
  14. ## $ bold : chr "hrbragg-pkg tab Inter Bold"
  15. ## $ bold_italic : chr "hrbragg-pkg tab Inter Bold Italic"
  16. ## $ ultrabold : chr "hrbragg-pkg tab Inter Extra Bold"
  17. ## $ ultrabold_italic : chr "hrbragg-pkg tab Inter Extra Bold Italic"
  18. ## $ heavy : chr "hrbragg-pkg tab Inter Black"
  19. ## $ heavy_italic : chr "hrbragg-pkg tab Inter Black Italic"
  20. ## - attr(*, "family")= chr "Inter"
  21. data("feature_dict")
  22. feature_dict[feature_dict$tag %in% textshaping::get_font_features("Inter")[[1]],]
  23. ## # A tibble: 19 x 3
  24. ## tag long_name description
  25. ## <chr> <chr> <chr>
  26. ## 1 aalt Access All Alternates Special feature: used to present user with choice all alternate forms of the charact…
  27. ## 2 calt Contextual Alternates Applies a second substitution feature based on a match of a character pattern within…
  28. ## 3 case Case Sensitive Forms Replace characters, especially punctuation, with forms better suited for all-capital…
  29. ## 4 ccmp Glyph Composition/Decomp… Either calls a ligature replacement on a sequence of characters or replaces a charac…
  30. ## 5 cpsp Capital Spacing Adjusts spacing between letters in all-capitals text
  31. ## 6 dlig Discretionary Ligatures Ligatures to be applied at the user's discretion
  32. ## 7 dnom Denominator Converts to appropriate fraction denominator form, invoked by frac
  33. ## 8 frac Fractions Converts figures separated by slash with diagonal fraction
  34. ## 9 kern Kerning Fine horizontal positioning of one glyph to the next, based on the shapes of the gly…
  35. ## 10 locl Localized Forms Substitutes character with the preferred form based on script language
  36. ## 11 mark Mark Positioning Fine positioning of a mark glyph to a base character
  37. ## 12 numr Numerator Converts to appropriate fraction numerator form, invoked by frac
  38. ## 13 ordn Ordinals Replaces characters with ordinal forms for use after numbers
  39. ## 14 pnum Proportional Figures Replaces numerals with glyphs of proportional width, often also onum
  40. ## 15 salt Stylistic Alternates Either replaces with, or displays list of, stylistic alternatives for a character
  41. ## 16 subs Subscript Replaces character with subscript version, cf. numr
  42. ## 17 sups Superscript Replaces character with superscript version, cf. dnom
  43. ## 18 tnum Tabular Figures Replaces numerals with glyphs of uniform width, often also lnum
  44. ## 19 zero Slashed Zero Replaces 0 figure with slashed 0

Let’s make a plot!

  1. ggplot() +
  2. geom_point(
  3. data = mtcars,
  4. aes(mpg, wt, color = factor(cyl))
  5. ) +
  6. geom_label(
  7. aes(
  8. x = 15, y = 5.48,
  9. label = "<- A fairly useless annotation\n that uses the custom Inter\n variant by default."
  10. ),
  11. label.size = 0, hjust = 0, vjust = 1
  12. ) +
  13. labs(
  14. x = "Fuel efficiency (mpg)", y = "Weight (tons)",
  15. title = "Seminal ggplot2 scatterplot example",
  16. subtitle = "A plot that is only useful for demonstration purposes",
  17. caption = "Brought to you by the letter 'g'"
  18. ) -> gg1

Dark & light mode support with just a parameter change!

  1. gg1 + theme_inter(grid = "XY", mode = "dark")

Note the ligatures aren’t as nice in Goldman Sans

  1. gg1 + theme_rc(grid = "XY", mode = "dark")

Note the ligatures aren’t as nice in or Roboto Condensed

  1. gg1 + theme_gs(grid = "XY", mode = "dark")

  1. gg1 + theme_inter(grid = "XY", mode = "light")

  1. gg1 + theme_rc(grid = "XY", mode = "light")

  1. gg1 + theme_gs(grid = "XY", mode = "light")

Making sure we got all the various plot components styled

  1. ggplot() +
  2. geom_point(
  3. data = mpg,
  4. aes(displ, hwy, color = trans)
  5. ) +
  6. facet_wrap(
  7. vars(cyl, drv), scales = "free", drop = TRUE
  8. ) +
  9. labs(
  10. x = "Displacement", y = "Highway",
  11. title = "Another seminal ggplot2 scatterplot example",
  12. subtitle = "A plot that is only useful for demonstration purposes",
  13. caption = "Brought to you by the letter 'g'"
  14. ) -> gg2
  1. gg2 + theme_inter(grid = "XY", mode = "light")

  1. gg2 + theme_inter(grid = "XY", mode = "dark")

Here’s a way to preview any variants you create:

  1. preview_variant(inter_pkg)

  1. reconfigure_font(
  2. family = "Trattatello",
  3. width = "normal",
  4. ligatures = "discretionary",
  5. calt = 1, tnum = 1, case = 1,
  6. dlig = 1, kern = 1,
  7. zero = 0, salt = 0
  8. ) -> trat
  9. preview_variant(trat)

  1. reconfigure_font(
  2. family = "Barlow",
  3. width = "normal",
  4. ligatures = "standard",
  5. tnum = 1, kern = 1
  6. ) -> barlow
  7. preview_variant(barlow)

hrbragg Metrics

Lang # Files (%) LoC (%) Blank lines (%) # Lines (%)
SVG 1 0.02 2574 0.35 0 0.00 0 0.00
R 21 0.46 977 0.13 158 0.39 679 0.46
Rmd 1 0.02 75 0.01 43 0.11 67 0.04
SUM 23 0.50 3626 0.50 201 0.50 746 0.50

clock Package Metrics for hrbragg

Code of Conduct

Please note that this project is released with a Contributor Code of
Conduct. By participating in this project you agree to abide by its
terms.