43

How to print angstrom square in x axis? I tried as follows.

labs(x = "x axis" (Å^2)", y = "y axis")
tjebo
  • 21,977
  • 7
  • 58
  • 94
sara
  • 433
  • 1
  • 4
  • 5

4 Answers4

38

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

akrun
  • 874,273
  • 37
  • 540
  • 662
30

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

zyurnaidi
  • 2,143
  • 13
  • 14
4

You could just simply use:

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

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)

tjebo
  • 21,977
  • 7
  • 58
  • 94