Closed graco-roza closed 3 years ago
I have read all the discussion on the use of HTML code with {glue}, {ggtext} and {ggplot2} in the facet titles using ggplot and element_markdown(), then I manage to use the example given by @clauswilke to generate the plot
element_markdown()
library(tidyverse) library(glue) #> #> Attaching package: 'glue' #> The following object is masked from 'package:dplyr': #> #> collapse library(ggtext) count(mtcars, cyl, carb) %>% mutate(cyl_lab = as.character( glue("Cylinders {cyl} <span style='color:red'>(n={n})</span>") )) %>% ggplot(aes(carb, n)) + geom_col() + facet_wrap(~cyl_lab) + theme( strip.text = element_markdown(), strip.text.x = element_markdown(), strip.text.y = element_markdown()
However, when applying strip.position = "left" or even switch = "y" in the facet function, the plot does not format the HTML code.
strip.position = "left"
switch = "y"
library(tidyverse) library(glue) #> #> Attaching package: 'glue' #> The following object is masked from 'package:dplyr': #> #> collapse library(ggtext) count(mtcars, cyl, carb) %>% mutate(cyl_lab = as.character( glue("Cylinders {cyl} <span style='color:red'>(n={n})</span>") )) %>% ggplot(aes(carb, n)) + geom_col() + facet_wrap(~cyl_lab, strip.position = "left") + theme( strip.text = element_markdown(), strip.text.x = element_markdown(), strip.text.y = element_markdown()
I searched for similar issues here but I couldn't find any. Also, if this is something related to the wrong use of functions I apologize in advance.
See here: https://github.com/wilkelab/ggtext/issues/5#issuecomment-539155038 Same problem.
I have read all the discussion on the use of HTML code with {glue}, {ggtext} and {ggplot2} in the facet titles using ggplot and
element_markdown()
, then I manage to use the example given by @clauswilke to generate the plotHowever, when applying
strip.position = "left"
or evenswitch = "y"
in the facet function, the plot does not format the HTML code.I searched for similar issues here but I couldn't find any. Also, if this is something related to the wrong use of functions I apologize in advance.