'ggplot fails to put numbers in italic in facet title

I am trying to have some of my facets in italic text, at which point I noticed that my numbers do not become italic. I noticed the same behaviour in axis labels. Importantly, only partial parts of the labels or only some facets should be italic.

Is there any way to circumvent/fix this?

MWE:

library(ggplot2)
library(tibble)
tibble(
    a = c('a1~italic(a1)', 'Not~Italic'),
    x = c(1,1),
    y = c(1,1)
) %>% 
    ggplot(aes(x,y)) + 
    geom_point() +
    facet_grid(a~., labeller = label_parsed) + 
    theme(
        strip.text = element_text(size = 20)
    ) +
    xlab(expression(italic(Italic~part~of~label1)~not~italic~part~of~label1))

Created on 2022-03-02 by the reprex package (v2.0.0)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source