Skip to content

Data Science Tutorials

  • Home
  • R
  • Statistics
  • Course
  • Machine Learning
  • Guest Blog
  • Contact
  • About Us
  • Toggle search form
  • How to change the column positions in R?
    How to change the column positions in R? R
  • Best Books on Data Science with Python
    Best Books on Data Science with Python Course
  • gganatogram Plot in R
    How to create Anatogram plot in R R
  • How to Use “not in” operator in Filter
    How to Use “not in” operator in Filter R
  • Hypothesis Testing Examples
    Hypothesis Testing Examples-Quick Overview Statistics
  • Get the first value in each group in R
    Get the first value in each group in R? R
  • Checking Missing Values in R
    Checking Missing Values in R R
  • How to add columns to a data frame in R
    How to add columns to a data frame in R 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:

How to Add Superscripts and Subscripts to Plots in R?

Posted on July 29July 29 By Jim No Comments on How to Add Superscripts and Subscripts to Plots in R?
Tweet
Share
Share
Pin

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.

Tweet
Share
Share
Pin
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

  • How to do Conditional Mutate in R
    How to do Conditional Mutate in R? R
  • gganatogram Plot in R
    How to create Anatogram plot in R R
  • Calculate the p-Value from Z-Score in R
    Calculate the p-Value from Z-Score in R R
  • Dealing Missing values in R
    Dealing With Missing values in R R
  • Select the First Row by Group in R
    Select the First Row by Group in R R
  • Remove Columns from a data frame
    How to Remove Columns from a data frame in R R

Leave a Reply Cancel reply

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

  • About Us
  • Contact
  • Disclaimer
  • Guest Blog
  • Privacy Policy
  • YouTube
  • Twitter
  • Facebook
  • Top 7 Skills Required to Become a Data Scientist
  • Learn Hadoop for Data Science
  • How Do Online Criminals Acquire Sensitive Data
  • Top Reasons To Learn R in 2023
  • Linear Interpolation in R-approx

Check your inbox or spam folder to confirm your subscription.

 https://www.r-bloggers.com
  • Top 10 Data Visualisation Tools
    Top 10 Data Visualisation Tools Every Data Science Enthusiast Must Know Course
  • Augmented Dickey-Fuller Test in R
    Augmented Dickey-Fuller Test in R R
  • Best online course for R programming
    Best online course for R programming Course
  • Calculate the p-Value from Z-Score in R
    Calculate the p-Value from Z-Score in R R
  • Box Cox transformation in R
    Box Cox transformation in R R
  • Add new calculated variables to a data frame and drop all existing variables
    Add new calculated variables to a data frame and drop all existing variables R
  • Data Science Applications in Banking
    Data Science Applications in Banking Machine Learning
  • What is the best way to filter by row number in R?
    What is the best way to filter by row number in R? R

Copyright © 2023 Data Science Tutorials.

Powered by PressBook News WordPress theme