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
:
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
:
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))
How to change font for greek letters in R plot
Use varphi
instead of phi
text(2,9, expression(varphi["1,2"]), cex=2)
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))))
Related Topics
Print R-Squared for All of the Models Fit with Lmlist
How Is Data Passed from Reactive Shiny Expression to Ggvis Plot
How to Reverse Legend (Labels and Color) So High Value Starts at Bottom
How to Transpose a Tibble() in R
How to Make Single Stacked Bar Chart in Ggplot2
Iteratively Constructed Dataframe in R
How to Create an Infix %Between% Operator
Change a Column from Birth Date to Age in R
Extract Name of Data.Frame in R as Character
Replace a Subset of a Data Frame with Dplyr Join Operations
Intersecting Points and Polygons in R
How to Perform a Pairwise T.Test in R Across Multiple Independent Vectors
Calculate Summary Statistics (E.G. Mean) on All Numeric Columns Using Data.Table
Determine Season from Date Using Lubridate in R
Transpose Only Certain Columns in Data.Frame