You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

288 lines
10 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. [![Project Status: Active – The project has reached a stable, usable
  2. state and is being actively
  3. developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
  4. [![Signed
  5. by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr)
  6. ![Signed commit
  7. %](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg)
  8. [![Linux build
  9. Status](https://travis-ci.org/hrbrmstr/hrbragg.svg?branch=master)](https://travis-ci.org/hrbrmstr/hrbragg)
  10. ![Minimal R
  11. Version](https://img.shields.io/badge/R%3E%3D-3.6.0-blue.svg)
  12. ![License](https://img.shields.io/badge/License-MIT-blue.svg)
  13. # hrbragg
  14. Typography-centric Themes, Theme Components, and Utilities for ‘ggplot2’
  15. and ‘ragg’.
  16. ## Description
  17. The ‘ragg’, ‘systemfonts’, and ‘textshaping’ packages make it possible
  18. to create plot components and themes that make full use of the rich
  19. typography features in modern fonts. Fonts, themes, and utilities are
  20. provided to create ‘ggplot2’ plots intended for rendering on ‘ragg’
  21. graphics devices.
  22. ## What’s Inside The Tin
  23. The following functions are implemented:
  24. - `adaptive_color`: Adaptive colors colors for hrbragg themes
  25. - `elb`: Shortcut for element\_blank
  26. - `ell`: Shortcut for element\_line
  27. - `elr`: Shortcut for element\_rect
  28. - `elt`: Shortcut for element\_text
  29. - `feature_dict`: OpenType feature description lookup table
  30. - `gs_pkg`: Goldman Sans & Goldman Sans Condensed Font Variants
  31. - `install_goldman_sans`: Install Goldman Sans
  32. - `install_inter`: Install Inter
  33. - `install_roboto_condensed`: Install Roboto Condensed
  34. - `inter_pkg`: Inter Font Variants
  35. - `opentype_typographic_features`: OpenType Typographic Features
  36. - `preview_variant`: Preview numbers, kerning, and ligatures from font
  37. variants you create
  38. - `rc_pkg`: Roboto Condensed Font Variants
  39. - `reconfigure_font`: Create an complete, alternate font family with
  40. the same customized features
  41. - `reset_ggplot2_defaults`: Restore all ggplot2 geom to default
  42. aesthetics
  43. - `scale_x_percent`: X & Y scales with opinionated pre-sets for
  44. percent & comma label formats
  45. - `theme_gs`: ggplot2 Theme Based On The Goldman Sans Font Family
  46. - `theme_inter`: ggplot2 Theme Based On The Inter Font Family
  47. - `theme_rc`: ggplot2 Theme Based On The Roboto Condensed Font Family
  48. ## Installation
  49. ``` r
  50. remotes::install_git("https://git.rud.is/hrbrmstr/hrbragg.git")
  51. # or
  52. remotes::install_gitlab("hrbrmstr/hrbragg")
  53. # or
  54. remotes::install_bitbucket("hrbrmstr/hrbragg")
  55. # or
  56. remotes::install_github("hrbrmstr/hrbragg")
  57. ```
  58. NOTE: To use the ‘remotes’ install options you will need to have the
  59. [{remotes} package](https://github.com/r-lib/remotes) installed.
  60. ## Usage
  61. ``` r
  62. library(tibble)
  63. library(hrbragg)
  64. library(ggplot2)
  65. # current version
  66. packageVersion("hrbragg")
  67. ## [1] '0.1.0'
  68. ```
  69. For the moment, you’ll need to install Inter:
  70. ``` r
  71. install_inter()
  72. ```
  73. ### Inspect the definitions of the feature codes:
  74. ``` r
  75. str(inter_pkg, 1)
  76. ## List of 17
  77. ## $ ultralight : chr "hrbragg-pkg tab Inter Thin"
  78. ## $ ultralight_italic: chr "hrbragg-pkg tab Inter Thin Italic"
  79. ## $ light : chr "hrbragg-pkg tab Inter Extra Light"
  80. ## $ light_italic : chr "hrbragg-pkg tab Inter Extra Light Italic"
  81. ## $ normal_italic : chr "hrbragg-pkg tab Inter Light Italic"
  82. ## $ normal : chr "hrbragg-pkg tab Inter Regular"
  83. ## $ normal_light : chr "hrbragg-pkg tab Inter Light"
  84. ## $ medium_italic : chr "hrbragg-pkg tab Inter Medium Italic"
  85. ## $ medium : chr "hrbragg-pkg tab Inter Medium"
  86. ## $ semibold_italic : chr "hrbragg-pkg tab Inter Semi Bold Italic"
  87. ## $ semibold : chr "hrbragg-pkg tab Inter Semi Bold"
  88. ## $ bold : chr "hrbragg-pkg tab Inter Bold"
  89. ## $ bold_italic : chr "hrbragg-pkg tab Inter Bold Italic"
  90. ## $ ultrabold : chr "hrbragg-pkg tab Inter Extra Bold"
  91. ## $ ultrabold_italic : chr "hrbragg-pkg tab Inter Extra Bold Italic"
  92. ## $ heavy : chr "hrbragg-pkg tab Inter Black"
  93. ## $ heavy_italic : chr "hrbragg-pkg tab Inter Black Italic"
  94. ## - attr(*, "family")= chr "Inter"
  95. data("feature_dict")
  96. feature_dict[feature_dict$tag %in% textshaping::get_font_features("Inter")[[1]],]
  97. ## # A tibble: 19 x 3
  98. ## tag long_name description
  99. ## <chr> <chr> <chr>
  100. ## 1 aalt Access All Alternates Special feature: used to present user with choice all alternate forms of the charact…
  101. ## 2 calt Contextual Alternates Applies a second substitution feature based on a match of a character pattern within…
  102. ## 3 case Case Sensitive Forms Replace characters, especially punctuation, with forms better suited for all-capital…
  103. ## 4 ccmp Glyph Composition/Decomp… Either calls a ligature replacement on a sequence of characters or replaces a charac…
  104. ## 5 cpsp Capital Spacing Adjusts spacing between letters in all-capitals text
  105. ## 6 dlig Discretionary Ligatures Ligatures to be applied at the user's discretion
  106. ## 7 dnom Denominator Converts to appropriate fraction denominator form, invoked by frac
  107. ## 8 frac Fractions Converts figures separated by slash with diagonal fraction
  108. ## 9 kern Kerning Fine horizontal positioning of one glyph to the next, based on the shapes of the gly…
  109. ## 10 locl Localized Forms Substitutes character with the preferred form based on script language
  110. ## 11 mark Mark Positioning Fine positioning of a mark glyph to a base character
  111. ## 12 numr Numerator Converts to appropriate fraction numerator form, invoked by frac
  112. ## 13 ordn Ordinals Replaces characters with ordinal forms for use after numbers
  113. ## 14 pnum Proportional Figures Replaces numerals with glyphs of proportional width, often also onum
  114. ## 15 salt Stylistic Alternates Either replaces with, or displays list of, stylistic alternatives for a character
  115. ## 16 subs Subscript Replaces character with subscript version, cf. numr
  116. ## 17 sups Superscript Replaces character with superscript version, cf. dnom
  117. ## 18 tnum Tabular Figures Replaces numerals with glyphs of uniform width, often also lnum
  118. ## 19 zero Slashed Zero Replaces 0 figure with slashed 0
  119. ```
  120. ### Let’s make a plot!
  121. ``` r
  122. ggplot() +
  123. geom_point(
  124. data = mtcars,
  125. aes(mpg, wt, color = factor(cyl))
  126. ) +
  127. geom_label(
  128. aes(
  129. x = 15, y = 5.48,
  130. label = "<- A fairly useless annotation\n that uses the custom Inter\n variant by default."
  131. ),
  132. label.size = 0, hjust = 0, vjust = 1
  133. ) +
  134. labs(
  135. x = "Fuel efficiency (mpg)", y = "Weight (tons)",
  136. title = "Seminal ggplot2 scatterplot example",
  137. subtitle = "A plot that is only useful for demonstration purposes",
  138. caption = "Brought to you by the letter 'g'"
  139. ) -> gg1
  140. ```
  141. ### Dark & light mode support with just a parameter change!
  142. ``` r
  143. gg1 + theme_inter(grid = "XY", mode = "dark")
  144. ```
  145. <img src="man/figures/README-dark-mode-01-1.png" width="672" />
  146. Note the ligatures aren’t as nice in Goldman Sans
  147. ``` r
  148. gg1 + theme_rc(grid = "XY", mode = "dark")
  149. ```
  150. <img src="man/figures/README-dark-mode-01-rc-1.png" width="672" />
  151. ### Note the ligatures aren’t as nice in or Roboto Condensed
  152. ``` r
  153. gg1 + theme_gs(grid = "XY", mode = "dark")
  154. ```
  155. <img src="man/figures/README-dark-mode-01-gs-1.png" width="672" />
  156. ``` r
  157. gg1 + theme_inter(grid = "XY", mode = "light")
  158. ```
  159. <img src="man/figures/README-light-mode-01-1.png" width="672" />
  160. ``` r
  161. gg1 + theme_rc(grid = "XY", mode = "light")
  162. ```
  163. <img src="man/figures/README-light-mode-01-rc-1.png" width="672" />
  164. ``` r
  165. gg1 + theme_gs(grid = "XY", mode = "light")
  166. ```
  167. <img src="man/figures/README-light-mode-01-gs-1.png" width="672" />
  168. ### Making sure we got all the various plot components styled
  169. ``` r
  170. ggplot() +
  171. geom_point(
  172. data = mpg,
  173. aes(displ, hwy, color = trans)
  174. ) +
  175. facet_wrap(
  176. vars(cyl, drv), scales = "free", drop = TRUE
  177. ) +
  178. labs(
  179. x = "Displacement", y = "Highway",
  180. title = "Another seminal ggplot2 scatterplot example",
  181. subtitle = "A plot that is only useful for demonstration purposes",
  182. caption = "Brought to you by the letter 'g'"
  183. ) -> gg2
  184. ```
  185. ``` r
  186. gg2 + theme_inter(grid = "XY", mode = "light")
  187. ```
  188. <img src="man/figures/README-light-mode-02-1.png" width="1400" />
  189. ``` r
  190. gg2 + theme_inter(grid = "XY", mode = "dark")
  191. ```
  192. <img src="man/figures/README-dark-mode-02-1.png" width="1400" />
  193. ### Here’s a way to preview any variants you create:
  194. ``` r
  195. preview_variant(inter_pkg)
  196. ```
  197. <img src="man/figures/README-preview-00-1.png" width="600" />
  198. ``` r
  199. reconfigure_font(
  200. family = "Trattatello",
  201. width = "normal",
  202. ligatures = "discretionary",
  203. calt = 1, tnum = 1, case = 1,
  204. dlig = 1, kern = 1,
  205. zero = 0, salt = 0
  206. ) -> trat
  207. preview_variant(trat)
  208. ```
  209. <img src="man/figures/README-preview-01-1.png" width="400" />
  210. ``` r
  211. reconfigure_font(
  212. family = "Barlow",
  213. width = "normal",
  214. ligatures = "standard",
  215. tnum = 1, kern = 1
  216. ) -> barlow
  217. preview_variant(barlow)
  218. ```
  219. <img src="man/figures/README-preview-02-1.png" width="600" />
  220. ## hrbragg Metrics
  221. | Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
  222. |:-----|---------:|-----:|-----:|-----:|------------:|-----:|---------:|-----:|
  223. | SVG | 1 | 0.02 | 2574 | 0.35 | 0 | 0.00 | 0 | 0.00 |
  224. | R | 21 | 0.46 | 977 | 0.13 | 158 | 0.39 | 679 | 0.46 |
  225. | Rmd | 1 | 0.02 | 75 | 0.01 | 43 | 0.11 | 67 | 0.04 |
  226. | SUM | 23 | 0.50 | 3626 | 0.50 | 201 | 0.50 | 746 | 0.50 |
  227. clock Package Metrics for hrbragg
  228. ## Code of Conduct
  229. Please note that this project is released with a Contributor Code of
  230. Conduct. By participating in this project you agree to abide by its
  231. terms.