Support different font weights with ggtext
Opened this issue · 0 comments
long39ng commented
Thank you very much for the package. Makes it so much fun to work with fonts.
One thing I would really like to have working is the ability to display normal and bold text inside the same element using ggtext. Currently, using fonts registered with reconfigure_font
does not seem to work, as opposed to registering via systemfonts::register_variant
.
Combining regular and italic text works fine on the other hand.
library(ragg)
library(hrbragg)
#> Please run `install_goldman_sans()`. This is only an interim requirement.
library(ggplot2)
library(ggtext)
lora_tnum <- reconfigure_font("Lora", tnum = 1)
ggplot() +
geom_richtext(
aes(0, 0, label = "1234 **Bold text**<br>4321 _Italic text_", hjust = 0),
size = 6, family = lora_tnum$normal
) +
ggtitle("hrbragg::reconfigure_font ❌") +
theme_void()
register_variant("Lora Tabular",
family = "Lora",
weight = c("normal", "bold"),
features = font_feature(tnum = 1))
ggplot() +
geom_richtext(
aes(0, 0, label = "1234 **Bold text**<br>4321 _Italic text_", hjust = 0),
size = 6, family = "Lora Tabular"
) +
ggtitle("systemfonts::register_variant ✔️") +
theme_void()
Created on 2021-02-21 by the reprex package (v1.0.0)
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.4 (2021-02-15)
#> os openSUSE Leap 15.2
#> system x86_64, linux-gnu
#> ui X11
#> language
#> collate en_GB.UTF-8
#> ctype en_GB.UTF-8
#> tz Europe/Berlin
#> date 2021-02-21
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.2)
#> backports 1.2.1 2020-12-09 [1] RSPM (R 4.0.3)
#> cli 2.3.0 2021-01-31 [1] RSPM (R 4.0.3)
#> colorspace 2.0-0 2020-11-11 [1] RSPM (R 4.0.3)
#> crayon 1.4.1 2021-02-08 [1] RSPM (R 4.0.3)
#> curl 4.3 2019-12-02 [1] CRAN (R 4.0.2)
#> DBI 1.1.1 2021-01-15 [1] RSPM (R 4.0.3)
#> digest 0.6.27 2020-10-24 [1] RSPM (R 4.0.3)
#> dplyr 1.0.4 2021-02-02 [1] RSPM (R 4.0.3)
#> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.2)
#> farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.2)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> generics 0.1.0 2020-10-31 [1] RSPM (R 4.0.3)
#> ggplot2 * 3.3.3 2020-12-30 [1] RSPM (R 4.0.3)
#> ggtext * 0.1.1 2020-12-17 [1] RSPM (R 4.0.3)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
#> gridtext 0.1.4 2020-12-10 [1] RSPM (R 4.0.3)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.2)
#> highr 0.8 2019-03-20 [1] CRAN (R 4.0.2)
#> hrbragg * 0.1.0 2021-02-20 [1] Github (hrbrmstr/hrbragg@1d96faf)
#> htmltools 0.5.1.1 2021-01-22 [1] RSPM (R 4.0.3)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.0.2)
#> knitr 1.31 2021-01-27 [1] RSPM (R 4.0.3)
#> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.3)
#> lifecycle 1.0.0 2021-02-15 [1] RSPM (R 4.0.3)
#> magrittr 2.0.1 2020-11-17 [1] RSPM (R 4.0.3)
#> markdown 1.1 2019-08-07 [1] CRAN (R 4.0.2)
#> mime 0.10 2021-02-13 [1] RSPM (R 4.0.3)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.2)
#> pillar 1.4.7 2020-11-20 [1] RSPM (R 4.0.3)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.2)
#> R6 2.5.0 2020-10-28 [1] RSPM (R 4.0.3)
#> ragg * 1.1.0 2021-02-15 [1] RSPM (R 4.0.3)
#> Rcpp 1.0.6 2021-01-15 [1] RSPM (R 4.0.3)
#> reprex 1.0.0 2021-01-27 [1] RSPM (R 4.0.3)
#> rlang 0.4.10 2020-12-30 [1] RSPM (R 4.0.3)
#> rmarkdown 2.7.1 2021-02-19 [1] Github (rstudio/rmarkdown@f8c23b6)
#> rstudioapi 0.13 2020-11-12 [1] RSPM (R 4.0.3)
#> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.2)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.2)
#> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> styler 1.3.2 2020-02-23 [1] RSPM (R 4.0.0)
#> systemfonts 1.0.1 2021-02-09 [1] RSPM (R 4.0.3)
#> textshaping 0.3.0 2021-02-10 [1] RSPM (R 4.0.3)
#> tibble 3.0.6 2021-01-29 [1] RSPM (R 4.0.3)
#> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.2)
#> uuid 0.1-4 2020-02-26 [1] CRAN (R 4.0.2)
#> vctrs 0.3.6 2020-12-17 [1] RSPM (R 4.0.3)
#> withr 2.4.1 2021-01-26 [1] RSPM (R 4.0.3)
#> xfun 0.21 2021-02-10 [1] RSPM (R 4.0.3)
#> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.2)
#>
#> [1] /home/long/R/x86_64-pc-linux-gnu-library/4.0
#> [2] /opt/R/4.0.4/lib/R/library