Home > Net >  Using TeX and Glue for title expression in base plots
Using TeX and Glue for title expression in base plots

Time:06-08

How can I use TeX and glue at the same time for a title expression? For example, I want to be able to use mathematical notations, but I also want to include the value of a dynamic variable with glue.

An example plot:

library(latex2exp)
library(glue)
v = "some dynamic text"
plot(5, 2, main=glue("{TeX('$I^2  $')}{v}"))

The latex expression is not used. Essentially, I need to use greek letters and subscripts and then glue a dynamic text at the end. Is there a way to include both mathematical expression and the glue function?

CodePudding user response:

You can simply use paste0() like this:

v = "some dynamic text"
plot(5, 2, main=TeX(paste0('$I^2  $',v)))
  • Related