How to print angstrom square in x axis? I tried as follows.
labs(x = "x axis" (Å^2)", y = "y axis")
Superscript is “started” by the caret ^ character. Anything after ^ is superscript. The superscript continues until you use a * or ~ character. If you want more text as superscript, then enclose it in quotes.
Subscripts and Superscripts To indicate a subscript, use the underscore _ character. To indicate a superscript, use a single caret character ^ . Note: this can be confusing, because the R Markdown language delimits superscripts with two carets.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With