Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot title containing math $\\times$ sign

Tags:

r

ggplot2

latex

I would like to include the mathematical sign for a multiplication (like the lower-case x) in a plot title.

I have tried using latex2exp to no avail - can someone help me with this?

The reprex code is this:

library(ggplot2)
library(latex2exp)
ggplot(data = data.frame(number = round(rnorm(200, mean=55, sd=5))),
       aes(x = number)) + geom_density() +
  ggtitle(TeX("Title containing times sign here: $\\times$"))

And it produces this outcome:

enter image description here

I would like the square (indicating an unrecognized sign) to display as this sign: enter image description here. It seems that other signs work (e.g. alpha) using this approach but I cannot figure out why the times sign poses an issue.

I'm not set on using latex2exp for the solution, as long as it works with the latex font (LM Roman 10).

Thanks a lot in advance.

like image 276
Ivo Avatar asked Sep 01 '26 02:09

Ivo


1 Answers

It works for me with plotmath facilities: the %*% operator displays as the times symbol. For example,

library(ggplot2)
ggplot(data = data.frame(number = round(rnorm(200, mean=55, sd=5))),
       aes(x = number)) + geom_density() +
  ggtitle(expression("Title containing times sign here: " %*% ""))

Created on 2021-06-14 by the reprex package (v2.0.0)

I think that is what latex2exp was trying to do, so it might be that on your system the times symbol was missing, which is why you got the box. Funny that the Unicode solution worked.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!