wilkelab / ggtext

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

Weird spacing when using <sup></sup> combined with Greek letter #68

Open FrancescoGarassino opened 3 years ago

FrancescoGarassino commented 3 years ago

Hi, and thank you for providing us with such a convenient package! I unfortunately ran into an issue I'd need some support for. I happen to use quite a lot units of measurements in my plots which are in the form of micrograms per squared meter, so I need to combine Greek letter mu and superscript (see an example below). However, when doing so I get a very weird spacing between my 'm' and the superscript 2.

library(ggplot2)
library(ggtext)

ggplot(data = iris, aes(x = (Petal.Length)^2, y = Petal.Width)) +
  geom_point() +
  xlab("Petal Length (&mu;g/m<sup>2</sup>)") +
  theme(axis.title.x = element_markdown())

Test1

I tried removing the Greek mu and everything seems to be working fine:

library(ggplot2)
library(ggtext)

ggplot(data = iris, aes(x = (Petal.Length)^2, y = Petal.Width)) +
  geom_point() +
  xlab("Petal Length<sup>2</sup>")+
  theme(axis.title.x = element_markdown())

Test2

Do you have a solution for this issue?

Thanks a lot in advance!

Matthionine commented 2 years ago

Hello @FrancescoGarassino Do you still experience this issue? I was curious and tried your example and here it works fine.

r 4.1.3 ggtext 0.1.1

chuyaowang commented 1 year ago

I had the same issue. The superscript worked fine before, but had a space before it when I ran the script after doing some other plotting. It seems to be related to how R uses the graphics device, as restarting R Studio resolved the issue.