How to use superscript with ggplot2

How to print an angstrom square on the x axis? I tried to do the following. I am very sorry for my simple question.

labs(x = "x axis" (Å^2)", y = "y axis") 
+8
r ggplot2
source share
2 answers

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

+11
source share

You should use the expression preferred in combination with paste, as follows:

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

enter image description here

+5
source share

All Articles