wilkelab / gridtext

Improved text rendering support for grid graphics in R
https://wilkelab.org/gridtext
Other
96 stars 17 forks source link

Math expression support #30

Closed adayim closed 1 year ago

adayim commented 1 year ago

Hi, this is a great package to draw text. I was wondering if it is possible to add math expression?

I want to have a line break in the math expression text, the only solution I can get is this. But the second line of the text aligned to the center. There's a package latex2exp is a good choice to draw Latex, but I am having a similar problem.

This package solved all my problems, but I can't find a better way to draw math symbols or equations. I tried to use the Unicode but the output seems to be off. Is it possible to add math expression with a better math font?


Here is what I did with this package.

library(grid)
txt <- "Heterogeneity: &tau;<sup>2</sup> = 0.22; &chi;<sup>2</sup> = 9.39"
gb <- gridtext::richtext_grob(txt, y = 0.7)
grid.newpage()
grid. Draw(gb)

The tau and chi looks like T and X. The grid. Text output looks like this:

grid.text(bquote("Heterogeneity:"~tau^2~" = 0.22;"~chi^2~" = 9.39"),
          y = 0.3)

Rplot

adayim commented 1 year ago

Found a discussion here. Will close it, sorry. I should have searched that.