How to print angstrom square in x axis? I tried as follows.
labs(x = "x axis" (Å^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()
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")
You could just simply use:
ggplot(mtcars, aes(hp, mpg)) + geom_point() + labs(x = x~axis~ring(A)^2, y = "y axis")
Another option is to use the ggtext package. It allows the use of markdown for labels, which I find easier to write and read.
library(ggtext)
library(ggplot2)
ggplot(mtcars, aes(hp, mpg)) +
labs(x = "x axis (Å^(2))", y = "y axis") +
## use markdown theme for simple superscripts
theme(axis.title.x = element_markdown())
Created on 2022-07-14 by the reprex package (v2.0.1)