How to use superscript with ggplot2

You should use expression, preferable combined with paste, as follow:

ggplot(mtcars, aes(hp, mpg)) + geom_point() + labs(x = expression(paste("x axis ", ring(A)^2)), y = "y axis")

enter image description here


You could just simply use:

ggplot(mtcars, aes(hp, mpg)) +  geom_point() +  labs(x = x~axis~ring(A)^2, y = "y axis")

We can use bquote

library(ggplot2)
ggplot(mtcars, aes(hp, mpg)) + 
       geom_point() +
       labs(x = bquote('x axis'~(Å^2)), y = "y axis") +
       #or
       #labs(x = bquote('x axis'~(ring(A)^2)), y = "y axis") 
       theme_bw()

enter image description here

Tags:

R

Ggplot2