rggplot2ggtextshowtext

Inter won't display in italic when rendered in ggplot with ggtext


Inter has italic specimens on Google Fonts, but the Inter you download with showtext::font_add_google() won't render as italics.

An example

library(tidyverse)
library(showtext)
library(ggtext)

font_add_google("Inter")
font_add_google("Roboto")

t0 <- tibble(
  x = 1,
  y = 4:1,
  lab = c(
    "This is Roboto",
    "<i>This is Roboto</i>",
    "This is Inter",
    "<i>This is Inter</i>"
    )
  )

showtext_auto()

t0 %>% 
  ggplot(
  aes(
    x, y, label = lab
    )
  ) +
  geom_richtext(
    fill = "grey95",
    family = "Roboto",
    size = 10,
    label.color = NA,
    data = t0 %>% 
      filter(
        lab %>% 
          str_detect("Roboto")
      )
  ) +
  geom_richtext(
    fill = "grey95",
    family = "Inter",
    size = 10,
    label.color = NA,
    data = t0 %>% 
      filter(
        lab %>% 
          str_detect("Inter")
      )
  ) 

enter image description here

As you can see, Roboto renders with italics but Inter does not.


Solution

  • Try changing font_add_google("Inter") to font_add_google("Inter", db_cache = FALSE). This forces the font to be downloaded using the official API rather than the cached version, and it's a bit more up to date. (The italic version might have been added more recently than the other versions).

    plot