0
ggplot() + 
    labs(x = "Bla")

I want to change the "Bla" label from the previous code so that it displays this equation:

enter image description here

However, I don't know how to include the intersection operator. Any help would be appreciated, thanks.

J. Doe
  • 1,544
  • 1
  • 11
  • 26
  • 1
    @YacineHajji Sorry, this includes absolutely zero information about the intersection operator – J. Doe May 11 '23 at 13:08
  • 1
    The search criteria you need to help find many many good examples on SO: `plotmath`. Reading [`?plotmath`](https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/plotmath.html) gives you a lot of information, and you can use `parse`, `expression`, or `bquote` for various needs. Try `ggplot() + labs(x = expression(Delta * over(A * bgroup("(", E[M] * intersect() * E[E], ")"), A * bgroup("(", E[E], ")"))))`. – r2evans May 11 '23 at 13:18
  • 1
    For starters, https://stackoverflow.com/q/35880053/3358272 has good examples. – r2evans May 11 '23 at 13:19

3 Answers3

2

Using ?plotmath you could add an intersection operator via intersect():

Note: Thx to @G.Grothendieck for teaching me that wrapping inside expression() is not needed.

library(ggplot2)

#xlab <- expression(Delta~frac(A(E[M]~intersect()~E[E]), A(E[E])))

xlab <- Delta~frac(A(E[M]~intersect()~E[E]), A(E[E]))

ggplot() + 
  labs(x = xlab)

stefan
  • 90,330
  • 6
  • 25
  • 51
2

From what I understand, you should use the latex2exp package to write the legend directly in Latex, as follows:

library(latex2exp)
library(ggplot2)
ggplot() +
  labs(x = TeX(r'($\Delta \frac{A(E_M \cap E_E)}{A(E_E)}$)'))
JGr
  • 86
  • 4
1

You can use unicode for symbols. For example \u0394 for delta and \u2229 for intersection.

library(ggplot2)
ggplot() + xlab(expression("\u0394"~frac(A(E[M]~"\u2229"~E[E]), A(E[E]))))

Created on 2023-05-11 with reprex v2.0.2

benson23
  • 16,369
  • 9
  • 19
  • 38