How to use superscript with ggplot2

2019-04-20 02:18发布

问题:

How to print angstrom square in x axis? I tried as follows. I am really sorry for my simple question.

labs(x = "x axis" (Å^2)", y = "y axis")

回答1:

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()



回答2:

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")



标签: r ggplot2