wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
650 stars 37 forks source link

defaults for "serif", "sans-serif", and "monospace" #107

Closed steveharoz closed 8 months ago

steveharoz commented 8 months ago

In a browser, you can use generic font-types for font families. For example `My website: <span style"font-family: monospace;">http://abcd.com

But that doesn't seem to work with ggtext. It'd be great if that ability was added for those of us who can never remember the names of fonts. Here are some web-safe fallbacks:

clauswilke commented 8 months ago

This is just handed off to the R graphics engine so you should be able to use the generic fonts that R knows. See e.g. here (was the first link I found, not otherwise relevant): https://cran.r-project.org/web/packages/svglite/vignettes/fonts.html

bwiernik commented 8 months ago
library(ggplot2)
mtcars |> 
  tibble::rownames_to_column(var = "model") |> 
  ggplot() + 
  aes(x = disp, y = mpg) + 
  ggtext::geom_richtext(
    aes(label = glue::glue("<span style='font-family:mono;'>{model}</span>"))
  )

Created on 2023-11-13 with reprex v2.0.2