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() no longer functioning with superscript in axis labels #109

Closed sjlussier closed 7 months ago

sjlussier commented 7 months ago

The most recent version of ggtext appears to no longer render superscript text as it functioned previously. Here is an example:

library(ggplot2) library(ggtext)

mtcars %>% ggplot(aes(x = wt, y = log2(mpg))) + geom_point() + scale_y_continuous(labels = glue("2^{1:6}"), breaks=1:6, limits = c(1, 6)) + theme(axis.text.y = ggtext::element_markdown())

bwiernik commented 7 months ago

The syntax is (and has always been):

library(ggplot)
library(ggtext)

mtcars %>%
ggplot(aes(x = wt, y = log2(mpg))) +
geom_point() +
scale_y_continuous(labels = glue("2<sup>{1:6}</sup>"), breaks=1:6, limits = c(1, 6)) +
theme(axis.text.y = ggtext::element_markdown())
sjlussier commented 7 months ago

Thanks for the quick reply! Interestingly, the syntax that I posted had worked previously -- but a very easy fix to change it as you suggested.

clauswilke commented 7 months ago

If it worked previously but now no longer then that's probably due to changes in the markdown package. You could file a report there.

> markdown::markdownToHTML("2^4", options = c("use_xhtml", "fragment_only"))
[1] "<p>2^4</p>\n"

Unfortunately markdown is not a standardized formatting language and different markdown-to-HTML converters accept different syntax or sometimes change syntax over time.