Text rendering is hard (for Thomas), but doesn’t have to be (for me)
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family 'FANCY FONT' not found in PostScript font database
Here is a family name and some text — go fetch
Rows: 181
Columns: 9
$ path <chr> "/tmp/RtmpqhYFuq/Barrio-regular.ttf", "/tmp/RtmpqhYFuq/Monte…
$ index <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
$ name <chr> "Barrio-Regular", "MonteCarlo-Regular", "Datalegreya-Thin", …
$ family <chr> "Barrio", "MonteCarlo", "Datalegreya", "Datalegreya", "Datal…
$ style <chr> "Regular", "Regular", "Thin", "Gradient", "Dot", "ExtraLight…
$ weight <ord> normal, normal, light, normal, bold, ultralight, ultralight,…
$ width <ord> normal, normal, normal, normal, normal, normal, normal, norm…
$ italic <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE,…
$ monospace <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALS…
add_fonts()
to register local font filesadd_fonts()
every time I start R~/fonts
or ./fonts
. These two locations will automatically get scanned when systemfonts is loadedget_from_google_fonts()
and get_from_font_squirrel()
Use require_font()
to ensure the font is installed from a web repository if missing (or error if it can’t be found there)
(this slideshow has require_font("Barrio")
in the beginning so it can render everywhere)
marquee uses cli-esque syntax for custom spans.
{.red color me red}
will change the color of text to red{#00FF00 color me green}
will change the color to green{.30 make me big}
will set the size to 30{.class put a class on it} will add the class
class` to the text
{.sub supscript}
and {.sup superscript}
are predefined custom spansNo markdown table support, but…
So far we have used the default style which matches standard (GitHub) markdown rendering
marquee provides a simple but powerful styling system
Each tag can be styled with 37 different properties
[1] "size" "background" "color"
[4] "family" "weight" "italic"
[7] "width" "features" "lineheight"
[10] "align" "tracking" "indent"
[13] "hanging" "margin_top" "margin_right"
[16] "margin_bottom" "margin_left" "padding_top"
[19] "padding_right" "padding_bottom" "padding_left"
[22] "border" "border_size_top" "border_size_right"
[25] "border_size_bottom" "border_size_left" "border_radius"
[28] "outline" "outline_width" "outline_join"
[31] "outline_mitre" "bullets" "underline"
[34] "strikethrough" "baseline" "img_asp"
[37] "text_direction"
NULL
value will get it’s value from the parentrel()
value will multiply the parent value with the rel valueem()
to make a value dependent on the text size of the elementrem()
to make a value dependent on the text size of the root elementskip_inherit()
to make a value uninheritableDon’t roll your own — modify
classic_style()
geom_marquee()
element_marquee()
guide_marquee()
geom_marquee()
geom_text()
/geom_label()
style
aesthetic with the other text-related aesthetics?geom_marquee()
penguins$outlier <- penguins$bill_len > 55 &
penguins$flipper_len < 190
penguins$text <- paste0(
"Suspecious *Pygoscelis ",
tolower(penguins$species),
"*"
)
style <- classic_style() |>
modify_style("body", outline = "white")
ggplot(
penguins,
aes(x = bill_len, y = flipper_len)
) +
geom_point(
aes(colour = I(ifelse(outlier, "red", "black")))
) +
geom_marquee(
aes(label = text),
data = penguins[penguins$outlier,],
style = style,
hjust = 1,
vjust = 1
)
geom_marquee()
element_marquee()
base
element in styleelement_marquee()
guide_marquee()
guide_marquee()
ggplot(penguins) +
geom_point(aes(x = bill_len, y = flipper_len, colour = species)) +
scale_color_discrete(
name = "
Overview of how bill length and flipper length relate to each other
in the penguin species *Adelie* <<1>>, *Chinstrap* <<2>>, and
*Gentoo* <<3>>.",
guide = guide_marquee(width = grid::unit(2.75, "in"))
)
guide_marquee()
ggplot(penguins) +
geom_point(aes(x = bill_len, y = flipper_len, colour = species)) +
scale_color_discrete(
name = "
Overview of how bill length and flipper length relate to each other
in the penguin species {.1 *Adelie*}, {.2 *Chinstrap*}, and
{.3 *Gentoo*}.",
guide = guide_marquee(width = grid::unit(2.75, "in"))
)
Next session: Styling your plot