Using Greek Letters in Plot Title

R allows users great flexibility in creating and formatting plots. Greek letters can be included in titles and labels using the expression command.

Example 1

If we want Greek letters embedded in the text of a title or label, we can use expression with paste:

Combining Expressions and Text

If you want to combine multiple mathematical expressions with text, use paste() inside expression(), as in the following.

latex2exp

latex2exp is an R package that parses and converts LaTeX math formulas to R’s plotmath expressions. Plotmath expressions are used to enter mathematical formulas and symbols to be rendered as text, axis labels, etc. throughout R’s plotting system. I find plotmath expressions to be quite opaque, while LaTeX is a de-facto standard for mathematical expressions, so this package might be useful to others as well.

The TeX function takes a LaTeX string and returns a plotmath expression suitable for use in plotting, e.g.,

expression(`$\alpha^\beta$` = paste("", "", alpha, , , , phantom()^{
    paste(beta, , , , "")
}))

Quickly test out what a translated LaTeX string would look like by using plot:

 [1] "\\%"           "\\,"           "\\;"           "\\aleph"      
 [5] "\\approx"      "\\ast"         "\\bar"         "\\bigcap"     
 [9] "\\bigcup"      "\\bullet"      "\\cdot"        "\\cdots"      
[13] "\\clubsuit"    "\\cong"        "\\degree"      "\\diamondsuit"
[17] "\\div"         "\\dot"         "\\equiv"       "\\exists"     
[21] "\\forall"      "\\frac"        "\\geq"         "\\hat"        
[25] "\\heartsuit"   "\\Im"          "\\in"          "\\infty"      
[29] "\\int"         "\\LaTeX"       "\\lbrack"      "\\ldots"      
[33] "\\leftarrow"   "\\Leftarrow"   "\\leq"         "\\lim"        
[37] "\\mathbf"      "\\mathit"      "\\mathrm"      "\\neg"        
[41] "\\neq"         "\\normalsize"  "\\notin"       "\\nsubset"    
[45] "\\oplus"       "\\oslash"      "\\otimes"      "\\overset"    
[49] "\\partial"     "\\perp"        "\\pm"          "\\prime"      
[53] "\\prod"        "\\propto"      "\\rbrack"      "\\Re"         
[57] "\\rightarrow"  "\\Rightarrow"  "\\sim"         "\\small"      
[61] "\\spadesuit"   "\\sqrt"        "\\subset"      "\\subseteq"   
[65] "\\sum"         "\\supset"      "\\supseteq"    "\\surd"       
[69] "\\TeX"         "\\textbf"      "\\textit"      "\\tilde"      
[73] "\\times"       "\\tiny"        "\\underline"  
 [ reached getOption("max.print") -- omitted 5 entries ]

[1] TRUE