Greek Letters in R Plot Label and Title

In R, plot symbols (Greek Letters in R Plot) are used to represent data points in scatter plots and other types of plots. These symbols can be customized to suit your preferences, making your data visualization more effective and aesthetically pleasing graphs or plots in R.

Common Plot Symbols in R

R Language uses numeric values to represent different symbols. The following is a list of the most commonly used plot symbols and their corresponding numbers:

SymbolCodeDescription
Circle1Solid circle (default)
Square15Solid square
Triangle2Solid triangle
Diamond18Solid diamond
Plus Sign3Plus sign
X4X marks the spot
Open Circle1Circle with no fill
Open Square0Square with no fill
Open Triangle17Triangle with no fill

Introduction to R Plot Symbols (Greek Letters)

The post is about writing (Greek Letters in) R plot symbols, their labels, and the title of the plots. There are two main ways to include Greek letters in your R plot labels (axis labels, title, legend):

  1. Using the expression Function
    This is the recommended approach as it provides more flexibility and control over the formatting of the Greek letters and mathematical expressions.
  2. Using raw Greek letter Codes
    This method is less common and requires memorizing the character codes for each Greek letter.

Question: How can one include Greek letters (symbols) in R plot labels?
Answer: Greek letters or symbols can be included in titles and labels of a graph using the expression command. Following are some examples

Note that in these examples, random data is generated from a normal distribution. You can use your own data set to produce graphs that have symbols or Greek letters in their labels or titles.

Greek Letters in R Plot

The following are a few examples of writing Greek letters in R plot.

Example 1: Draw Histogram

mycoef <- rnorm (1000)
hist(mycoef, main = expression(beta) )

where beta in expression is the Greek letter (symbol) of $\beta$. A histogram similar to the following will be produced.

greek Letters in r plot-1

Example 2:

sample <- rnorm(mean=5, sd=1, n=100)
hist(sample, main=expression( paste("sampled values, ", mu, "=5, ", sigma, "=1" )))

where mu and sigma are symbols of $\mu$ and $\sigma$ respectively. The histogram will look like

greek symbols in r plot-2

Example 3:

curve(dnorm, from= -3, to=3, n=1000, main="Normal Probability Density Function")

will produce a curve of Normal probability density function ranging from $-3$ to $3$.

greek symbols in r plot-3

List of Common Greek Letters in R Plot

The following is a list of common Greek letters and their corresponding R expressions:

Greek LetterR ExpressionR ExampleSymbol
Alphaalphaexpression(alpha)$\alpha$
Betabetaexpression(beta)$\beta$
Gammagammaexpression(gamma)$\gamma$
Deltadeltaexpression(delta)$delta$
Thetathetaexpression(theta)$theta$
Pipiexpression(pi)$\pi$
Sigmasigmaexpression(sigma)$\sigma$
Lambdalambdaexpression(lambda)$\lambda$
Rhorhoexpression(rho)$\rho$
Phiphiexpression(phi)$phi$
Mumuexpression(mu)$\mu$
Omegaomegaexpression(omega)$\omega$

Complex Mathematical Expressions in R Plot

One can also combine Greek Letters with other math functions like sum or integrals

# Plot with complex mathematical expression
x = runif(100)
y = runif(100)
plot(x, y, main=expression(paste("Sum: ", sum(x[i]^2), " for all ", i)))

Normal Density Function

To add a normal density function formula, we need to use the text and paste command, that is

text(-2, 0.3, expression(f(x) == paste(frac(1, sqrt(2*pi* sigma^2 ) ), " ", e^{frac(-(x-mu)^2, 2*sigma^2)})), cex=1.2)

Now, the updated curve of the Normal probability density function will be

Normal Probability Density Function

Example 4:

x <- dnorm( seq(-3, 3, 0.001))
plot(seq(-3, 3, 0.001), cumsum(x)/sum(x), 
           type="l", col="blue", xlab="x", 
           main="Normal Cumulative Distribution Function")

The Normal Cumulative Distribution function will look like

Normal Cumulative Distribution Function

To add the formula, use the text and paste command, that is

text(-1.5, 0.7, 
       expression(phi(x) == paste(frac(1, sqrt(2*pi)), " ", 
       integral(e^(-t^2/2)*dt, -infinity, x))), cex = 1.2)

The Curve of the Normal Cumulative Distribution Function

The Curve of the Normal Cumulative Distribution Function and its formula in the plot will look like this,

Normal Cumulative distribution

https://itfeature.com, https://gmstat.com

Leave a Reply

Discover more from R Programming FAQs

Subscribe now to keep reading and get access to the full archive.

Continue reading