Lesson 21 of 37
In Progress

Using custom fonts in R examples and exercises

Your Turn
  1. Take one of the charts we’ve made and add your own fonts to it
  2. Adjust the size or style of your text using theme elements
  3. Save your chart with the custom fonts

Make sure you’ve installed the ragg package.

Solutions

You find an example chart using custom fonts here.

Learn More

This blog post talks about modern text features in R using the ragg and systemfonts packages.

Have any questions? Put them below and we will help you out!

  1. I got one variation of the font that I want to work by using this:

    systemfonts::register_variant(
    name = “Segoe UI Custom Semibold”,
    family = “Segoe UI”,
    weight = “semibold”
    )

    However, I tried to do the same for a semilight version and it didn’t work:
    systemfonts::register_variant(
    name = “Segoe UI Custom Semilight”,
    family = “Segoe UI”,
    weight = “semilight”
    )

    For the latter I get “Error: No font with the given family name and weight/width settings available”.

    Am I missing something?

    1. It looks like “semilight” isn’t a weight that you can use. This is from the help file for register_variant():

      One or two of “thin”, “ultralight”, “light”, “normal”, “medium”, “semibold”, “bold”, “ultrabold”, or “heavy”. If one is given it sets the weight for the whole variant. If two is given the first one defines the plain weight and the second the bold weight. If NULL then the variants of the given family closest to “normal” and “bold” will be chosen.

      Does it work if you choose, says, ultralight?

  2. I am getting a similar error reported by someone earlier.
    This is my code
    register_variant(
    “Rockwell_custom”,
    Rockwell, weight = “semibold”,
    features = font_feature(ligatures = “discretionary”)
    )
    and this is my error:
    Error: No font with the given family name and weight/width settings available

      1. Thanks, I thought Rockwell_custom is a name I give for registering my variant with the family name Rockwell (which I wrote correctly). However, this doesn’t seem to work for me, I am a newbie in fonts and any help would be appreciated.
        Here is the reprex of my error.
        “` r
        library(systemfonts)
        library(tidyverse)
        systemfonts::system_fonts() |> as_tibble() |> filter(family==”Rockwell”)
        #> # A tibble: 4 × 9
        #> path index name family style weight width italic monos…¹
        #>
        #> 1 “C:\\WINDOWS\\Fonts\\ROC… 0 Rock… Rockw… Regu… normal norm… FALSE FALSE
        #> 2 “C:\\WINDOWS\\Fonts\\ROC… 0 Rock… Rockw… Bold bold norm… FALSE FALSE
        #> 3 “C:\\WINDOWS\\Fonts\\ROC… 0 Rock… Rockw… Bold… bold norm… TRUE FALSE
        #> 4 “C:\\WINDOWS\\Fonts\\ROC… 0 Rock… Rockw… Ital… normal norm… TRUE FALSE
        #> # … with abbreviated variable name ¹​monospace
        register_variant(family =
        “Rockwell”, weight = “semibold”)
        #> Error: No font with the given family name and weight/width settings available
        “`

        Created on 2023-03-13 with [reprex v2.0.2](https://reprex.tidyverse.org)