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
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()
)
Unfortunately the
font-variant
property is not supported byggtext
. According to the [docs] only (https://wilkelab.org/ggtext/articles/introduction.html):Hence achieving your desired result requires some manual work by converting your strings to uppercase and setting a small font size via
ggtext
.BTW: The style is set via
style
notclass
.