Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotmath expression with mathematical operators in ggplot2

I am still struggling with correct labels of my plots. I managed to get this to work.

df <-data.frame(a=seq(1,20),b=seq(1,20))
ggplot(df, aes(x = a, y = b)) + geom_point() +
  ylab(expression(paste(CH[4]~" formation rate"~"(",mu, mol, day^{-1},")")))

What it is missing is the operator sign " * " between mumol and day^-1. It should look like this: enter image description here Thank you for your help.

like image 447
nouse Avatar asked Nov 23 '25 09:11

nouse


1 Answers

I prefer not to use the paste style for expressions but to use ~ and * to separate terms with or without a space respectively. If you want an *, put it in quotes.

ggplot(df, aes(x = a, y = b)) + 
  geom_point() + 
  ylab(expression(CH[4]~formation~rate~(mu*mol~'*'~day^{-1}))) 
like image 105
Richard Telford Avatar answered Nov 24 '25 21:11

Richard Telford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!