Italic Greek Letters in R Plot

Italicise greek letters in ggplot

Extending on @Ben Bolker comment, you can work this out using Unicode characters for the Greek letters you want to italize / make bold. This will also work in case where you might want to to this by means of italic() or bold() functions within expression() calls.

In your case it is enough to replace mu with \u03BC, and sigma with \u03C3:

i3 <- iris %>% transform(Species = factor(ifelse(Species == "setosa", "italic(\u03BC)",
ifelse(Species == "versicolor", "bold(\u03C3)", "tau"))))

ggplot(i3, aes(Sepal.Width, Sepal.Length)) +
geom_point() +
facet_grid(.~Species, labeller = label_parsed)

Italic greek letters / latex-style math in plot titles

You may want to check out the tikzDevice package (or take a look at its vignette first), which provides a natural way to write LaTeX math in R graphics.

I also have a simple example here.

And here is another example:

library(tikzDevice)
library(ggplot2)
tikz('math.tex', standAlone = TRUE, width = 4, height = 4)
qplot(1:10, 1:10,
main = '$\\mathrm{d} \\mathbf{x} = a [\\theta - \\mathbf{x}] \\mathrm{d} t$')
dev.off()

which produces this if you run pdflatex math.tex:

latex math in ggplot2

Italic greek letters / latex-style math in plot titles

You may want to check out the tikzDevice package (or take a look at its vignette first), which provides a natural way to write LaTeX math in R graphics.

I also have a simple example here.

And here is another example:

library(tikzDevice)
library(ggplot2)
tikz('math.tex', standAlone = TRUE, width = 4, height = 4)
qplot(1:10, 1:10,
main = '$\\mathrm{d} \\mathbf{x} = a [\\theta - \\mathbf{x}] \\mathrm{d} t$')
dev.off()

which produces this if you run pdflatex math.tex:

latex math in ggplot2

using glue::glue to write plotmath expressions like italic fontface or greek letters

Instead of using substitute, a compact option would be bquote

lbl <- bquote("The estimate for"~.(res$term[2])~is ~italic(beta) == .(res$statistic[2]))

cowplot::ggdraw(cowplot::add_sub(
plot = ggplot(data.frame()) +
geom_point() +
xlim(0, 10) +
ylim(0, 100),
label = lbl))

Sample Image

How to change font for greek letters in R plot

Use varphi instead of phi

text(2,9, expression(varphi["1,2"]), cex=2) 

Sample Image

text() to display a greek letter with subscript in R plot

Check out ?plotmath for relevant examples of how to piece this sort of thing together. For instance, here's one adapted from the "## How to combine "math" and numeric variables :"

curve(dnorm(x,175.3,.961),160,190,type="l")
sigmam <- dnorm(177.4,175.3,.961)/ dnorm(177.4,176,4)

text(165,.285, bquote(Sigma[m] == .(round(sigmam,2))))

Sample Image



Related Topics



Leave a reply



Submit