[R] strange behavior of plotmath

S Ellison S@E|||@on @end|ng |rom LGCGroup@com
Mon May 21 16:52:16 CEST 2018


> plot(1:10, xlab = expression(NO[3]^-~(mg/L)))
It's unexpected but not inexplicable.
The difficulty is that the superscript begins with a unary minus operator. It _must_ have something (number or variable) after it to negate. Since the thing following the '-' is not a number, plotmath has just taken the entire following string as part of an unlikely (but technically possible) variable name "~(mg/L)". 

Rui Barradas' corrected form creates the '-' as a string, preventing the inappropriate mathematical interpretation.

You don't actually _need_ the enclosiong {}, though;
> expression(NO[3]^'-'~(mg/L))
works as you intended

S Ellison


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}




More information about the R-help mailing list