R tableGrob plot numbers in scientific notation in plotmath

123 views Asked by At

I'd like to plot a table in R using tableGrob containing numbers which should display in scientific notation in math mode, such as 2.45x10⁵.

I tried using format(x,scientific=TRUE) but it only displays as 2.45e+5. If I pass theme=ttheme_default(core=list(fg_params=list(parse=TRUE))), it discards formatting for some numbers and just shows plain decimal number.

library(gridExtra)
x<-matrix(c(4.5*10^-5,2.33*10^5))
tt<-ttheme_default(core=list(fg_params=list(parse=TRUE)))
plot(tableGrob(format(x,scientific=TRUE),theme=tt))

The output shows:

4.5e-05
233000

I'd rather want:

4.50×10⁻⁵
2.33×10⁵
0

There are 0 answers