plot - Variable part in an expression( ... ) with R -
this question has answer here:
- use variable within plotmath expression 2 answers
i display physical units in r plot. in order have better typography, use expression function way:
plot(rnorm(10),rnorm(10),main=expression(µg.l^-1))
suppose unit not statically known, , given variable [unit]:
unit = 'µg.l^-1' plot(rnorm(10),rnorm(10),main=expression(unit))
this of course not work because [unit] not substituted value. there means achieve anyway?
edit: should stress main difficulty here unit displayed sent string plot function. contents of unit
should interpreted expression @ point (that transformed string expression object), , answer texb comes handy. please unmark question duplicate, since use of parse
fundamental here , not mentionned in post suggest.
how about:
unit = 'µg.l^-1' plot(rnorm(10),rnorm(10),main=parse(text=unit))
Comments
Post a Comment