Angela Russell
Angela Russell

Reputation: 143

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

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.

Upvotes: 2

Views: 957

Answers (2)

TarJae
TarJae

Reputation: 78927

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

Upvotes: 1

Shibaprasad
Shibaprasad

Reputation: 1332

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

Upvotes: 3

Related Questions