Get access to all lessons in this course.
-
The shape of data
- Chart types
- How to choose a chart
- Visual metaphor
- Memorability vs. speed of comprehension
- Identifying your audience
- Data encoding process
-
Layout
- Grids, borders, lines
- Axes
- Grids, borders, lines, and axes examples and exercises
- Alignment
- White space
- Charts in larger layouts
- Alignment, white space, and layout of multiple plots examples and exercises
-
Typography
- What is typography and why does it matter?
- Typographic hierarchy
- Font styles
- Good fonts and where to find them
- Using custom fonts in R examples and exercises
- ggtext examples and exercises
- Pairing fonts
- Typography beyond charts
-
Color
- Color palettes
- Color examples and exercises
- Color models
- HCL color palettes in ggplot examples and exercises
- The color wheel
- Color and emotion
- The eyedropper tool and color inspiration
-
Special topics
- Legends
- Accessibility
- Combining ggplot with a vector editor
- Annotations
- Resizing plots for export
- Finding inspiration
The Glamour of Graphics
Using custom fonts in R examples and exercises
This lesson is locked
This lesson is called Using custom fonts in R examples and exercises, part of the The Glamour of Graphics course. This lesson is called Using custom fonts in R examples and exercises, part of the The Glamour of Graphics course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Your Turn
Take one of the charts we’ve made and add your own fonts to it
Adjust the size or style of your text using theme elements
Save your chart with the custom fonts
Make sure you’ve installed the ragg
package.
Learn More
This blog post talks about modern text features in R using the ragg
and systemfonts
packages.
You need to be signed-in to comment on this post. Login.
Blayne Beacham
February 20, 2023
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?
David Keyes
February 21, 2023
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?
Blayne Beacham
March 8, 2023
Sorry for the late reply (started a new job). "light" did the trick!
Thanks so much. My viz game just took a nice jump up with these fonts!
David Keyes
March 8, 2023
Awesome, glad it worked!
soundarya soundararajan
March 9, 2023
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
David Keyes
March 9, 2023
Are you sure the font is called "Rockwell_custom" (and not, for example, "Rockwell custom" or "Rockwell" or "Rockwell Custom")? You have to enter the exact name as it appears in the family column when you run
systemfonts::system_fonts()
. See https://show.rfor.us/RfczclV1soundarya soundararajan
March 13, 2023
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.
Created on 2023-03-13 with reprex v2.0.2
David Keyes
March 13, 2023
I'd need to see a little bit more in order to see the full text in the family column. Can you share that?
Blayne Beacham
August 28, 2023
I have another question about what might be possible with . Instead of 'hard-coding' text between the span tags, is it possible to use a variable instead (so the text can be dynamic depending on the data)?
Here is an example of what I am trying to do:
This runs fine, but I would prefer to not 'hard code' in 'Biscoe' and instead use a variable like max_height_island. When I try to do this it just shows up as "max_height_island". I recall from your RMarkdown stuff that you can run some inline stuff with `r but I'm not sure if there is an equivalent here. Any thoughts?
Blayne Beacham
August 28, 2023
Shoot. It looks like the "span" tags got scrubbed when I published the comment. Do you get what I mean?
I basically want to turn one word in a sentence into a different colour (that aligns with the colour I have in the graph) but I want the word to be based on a variable that I create rather than manually typing it in (in this way I can do functions with it to produce a lot of reports/graphs without hard-coding the highlighted name)
David Keyes
August 28, 2023
Yup, you can definitely do this. Here's a quick video explanation.
BTW, on the new website, you can add code chunks (same as you would in RMarkdown) to keep the formatting of code. I fixed your question below so the span shows up.