简体   繁体   中英

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: 在此处输入图片说明 Thank you for your help.

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}))) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM