Search code examples
rplotlatexlegendplotmath

Having latex-like math formula in the legend


I know how to generate this in the legend:

N_{1}(\alpha)

which can be done via

expression(N[1](alpha))

But I need something like this in latex:

N_{1+}(\LargerCdot \alpha)

which I have no clue how to generate.


Solution

  • Here are a few options:

    1) Regular dot

    expression(N[1+NULL](NULL %.% alpha))
    

    2) Large dot: On the Mac, I used option + 8 to get the large dot.

    expression(paste(N[1+NULL],"(•", alpha,")"))
    expression(paste(N[1+NULL],"(",~"•",NULL~alpha,")"))
    

    Example using built-in iris data frame and ggplot2:

    library(ggplot2)
    
    ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
      geom_point(aes(colour=Species)) +
      scale_colour_discrete(labels=c(expression(N[1+NULL](NULL %.% alpha)), 
                                     expression(paste(N[1+NULL],"(•", alpha,")")),
                                     expression(paste(N[1+NULL],"(",~"•",NULL~alpha,")")))) +
      theme(legend.text=element_text(size=15))
    

    enter image description here