Home > OS >  Paste an object in addition to superscripts in ggplot labels
Paste an object in addition to superscripts in ggplot labels

Time:11-11

I'm trying to achieve two things in a ggplot label, being to paste an assigned character variable as well as some text with superscript into the same label. However, I've only been able to do either of those two things but I can't seem to do both at the same time.

name = "Mary"
ggplot()   ylab(expression(paste(name~"BMI"~kg/mm^2))) #this can only do the superscript but not get the name
ggplot()   ylab(paste(name,expression("BMI"~kg/mm^2))) #this can get the name but not the superscript

Any help is appreciated, thanks!

CodePudding user response:

Use bquote

ggplot()   ylab(bquote(.(name)~BMI~kg/mm^2))
  • Related