Skip to content

Data Science Tutorials

For Data Science Learners

  • Determine the significance of a mediation effect in R
    Determine the significance of a mediation effect in R R
  • Random Forest Machine Learning
    Random Forest Machine Learning Introduction R
  •  Identify positions in R R
  • Calculate the p-Value from Z-Score in R
    Calculate the p-Value from Z-Score in R R
  • bootstrapping-in-r
    Bootstrapping in R R
  • R-Change Number of Bins in Histogram R
  • Detecting and Dealing with Outliers
    Detecting and Dealing with Outliers: First Step R
  • Hypothesis Testing Examples
    Hypothesis Testing Examples-Quick Overview Statistics
How to Add Superscripts and Subscripts to Plots in R?, The basic syntax for adding superscripts or subscripts to charts in R is as follows:

How to Add Superscripts and Subscripts to Plots in R?

Posted on July 29July 29 By Admin No Comments on How to Add Superscripts and Subscripts to Plots in R?

How to Add Superscripts and Subscripts to Plots in R?, The basic syntax for adding superscripts or subscripts to charts in R is as follows.

ggplot2 Guide

define superscript expression

x.expression <- expression(x^3 ~ variable ~ label)

define subscript expression

y.expression <- expression(y[3] ~ variable ~ label)

axis labels with expressions

plot(x, y, xlab = x_expression, ylab = y_expression)

How to Add Superscripts and Subscripts to Plots in R?

These examples demonstrate how to apply this syntax in real-world situations.

Example 1: Axis labels with superscripts

The code below demonstrates how to add superscripts to an R plot’s axis labels.

Let’s create some data

x <- c(11, 12, 13, 14, 15, 16, 17, 18)
y <- c(9, 10, 19, 18, 12, 19, 16, 19)

create x and y-axis labels with superscripts

x.expression <- expression(x^3 ~ variable ~ label)
y.expression <- expression(y^3 ~ variable ~ label)

Now we can create a plot

plot(x, y, xlab = x.expression, ylab = y.expression)

Take note of the superscript in the labels of the x- and y-axes.

The graphic has a little gap where the y-axis superscript should be. With the help of R’s par() function, we can bring the axis labels closer to the plot.

adjust par values (default is (3, 0, 0))

par(mgp=c(2.5, 1, 0))
plot(x, y, xlab = x.expression, ylab = y.expression)

Remarkably, we selected “3” at random to go in the superscript. You are permitted to use any character or number as a superscript.

Example 2: Add Axis Labels with Subscripts

The code below demonstrates how to add subscripts to an axis label in an R plot.

x.expression <- expression(x[3] ~ variable ~ label)
y.expression <- expression(y[3] ~ variable ~ label)
plot(x, y, xlab = x.expression, ylab = y.expression)

Check your inbox or spam folder to confirm your subscription.

R

Post navigation

Previous Post: How to convert characters from upper to lower case in R?
Next Post: Best Books to Learn Statistics for Data Science

Related Posts

  • pheatmap function in R
    The pheatmap function in R R
  • How to Use Italic Font in R
    How to Use Italic Font in R R
  • Remove Columns from a data frame
    How to Remove Columns from a data frame in R R
  • How to Group and Summarize Data in R
    How to Group and Summarize Data in R R
  • Interactive 3d plot in R
    Interactive 3d plot in R-Quick Guide R
  • Change ggplot2 Theme Color in R
    Change ggplot2 Theme Color in R ggthemr Package R

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Best Prompt Engineering Books
  • Understanding Machine Learning and Data Science
  • Best Git Books
  • Top 5 Books to Learn Data Engineering
  • Mastering R Programming for Data Science: Tips and Tricks
  • About Us
  • Contact
  • Disclaimer
  • Privacy Policy

https://www.r-bloggers.com

  • YouTube
  • Twitter
  • Facebook
  • Course
  • Excel
  • Machine Learning
  • Opensesame
  • R
  • Statistics

Check your inbox or spam folder to confirm your subscription.

  • Add Significance Level and Stars to Plot in R
    Add Significance Level and Stars to Plot in R R
  • Mastering the map() Function in R R
  • what-is-epoch-in-machine-learning
    What is Epoch in Machine Learning? Machine Learning
  • Sort Data in R With Examples
    Sort Data in R With Examples R
  • Error: Can't rename columns that don't exist
    Can’t rename columns that don’t exist R
  • How to Find Unmatched Records in R
    How to Find Unmatched Records in R R
  • Number to Percentage in R
    Number to Percentage in R R
  • How to Use Bold Font in
    How to Use Bold Font in R with Examples R

Privacy Policy

Copyright © 2025 Data Science Tutorials.

Powered by PressBook News WordPress theme