How to get a subscript into an axis title in `ggplot`

Viewed 105

I want to have -1 in an axis title with the -1 being superscript. The title on my y axis should read "Ba:Ca (µmol:mol-1)" with the -1 as superscript. I have tried ^ before the -1 and also the expression function to no avail. R Rookie, please help.

2 Answers

Is this something you want?

set.seed(4)
x <- runif(20, 5, 10)
y <- runif(20, 15, 20)

df <- data.frame(x,y)

ggplot()+
  geom_point(data=df, aes(x,y))+
  labs(y = expression(paste('Ba:Ca (µmol:mol'^-1,')')), x = "x axis")

Output

Alternatively we could use bquote

ggplot()+
    geom_point(data=mtcars, aes(cyl,mpg))+
    labs(y = bquote('Ba:Ca'~(µmol<.mol^-1)))

enter image description here

Related