Search code examples
rggplot2legendlegend-properties

Using solar mass symbol in ggplot2 legend


I want to insert the solar mass symbol in a ggplot2 legend, but I do not know how.

I'v tried so far the expression() and TeX() functions (the last one is a function of the package latex2exp) but none of then have solved my problem.

Here is a sample of what I was trying to do:

library(ggplot2)
library(latex2exp)

ggplot() + 
  labs(x = expression(Log(Age/yr)),
       y = TeX("$\\odot$"))

Solution

  • I think that it's not the right (and elegant) answer but the following code worked

      labs(y = expression(Log(M[stellar]/M['☉'] ))))