wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
650 stars 37 forks source link

`element_markdown()` not fully working in theme argument `strip.text`? #82

Closed courtiol closed 2 years ago

courtiol commented 2 years ago

I don't know where the problem is coming from (me, my system, ggtext, ggplot2?) but it seems that markdown does not work properly inside the strips of a faceted plot.

Is this a bug or a known limitation? Is there a workaround? Thanks!

NB: I found an old related issue (https://github.com/tidyverse/ggplot2/issues/3557), but it seems to have been solved.

library(ggplot2)
library(ggtext)

ggplot(data = iris) +
  geom_point(aes(x = Sepal.Length, y = Petal.Length)) +
  facet_wrap(~ Species,
             labeller = labeller(Species = \(x) paste0("**", letters[nlevels(iris$Species)], "** ", x))) -> myplot

## This plot shows the strip labels before formatting (they look OK):
myplot

## I would have expected here the a, b, c to be bold:
myplot + theme(strip.text = ggtext::element_markdown())

## This is just to check that `ggtext::element_markdown()` can indeed generate a bold typeface on my system:
myplot + theme(strip.text = ggtext::element_markdown(face = "bold"))

Created on 2022-04-26 by the reprex package (v2.0.1)

clauswilke commented 2 years ago

Are you running R 4.2.0? The released version of gridtext is currently broken (https://github.com/wilkelab/gridtext/issues/24). A fix is on the way. You can install the development version of gridtext to work around this.

courtiol commented 2 years ago

You are correct and indeed updating {gridtext} solves the issue!