Home > Blockchain >  How can I write axis ticks in small capital using ggtext?
How can I write axis ticks in small capital using ggtext?

Time:04-19

I want to write axis ticks in small capital using ggtext::element_markdown(). However, an attempt like <span class='font-variant: small-caps'>small capital here!</span> is in vain. Then, how should I achieve that effect?

MWE

enter image description here

library(tidyverse)

tribble(
  ~ f1, ~ f2, ~ mean,
  "a",  "SBJ",  1212,
  "a",  "OBJ",  1313,
  "p",  "SBJ",  1515,
  "p",  "OBJ",  1616
) |>
  mutate(
    f2 = fct_relevel(
      f2,
      c(
        "SBJ",
        "OBJ"
      )
    )
  ) |>
  ggplot(
    aes(
      x = f2,
      y = mean,
      fill = f1
    )
  )  
  scale_x_discrete(
    labels = c(
      "NP <span class='font-variant: small-caps'>sbj</span>",
      "NP <span class='font-variant: small-caps'>obj</span>"
    )
  )  
  geom_col(
    position = 'dodge',
    size = 1
  )  
  theme(
    axis.text.x = ggtext::element_markdown()
  )

CodePudding user response:

Unfortunately the font-variant property is not supported by ggtext. According to the [docs] only (enter image description here

  • Related