[R] [Q] use of expression() in plot() vs. hist()

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Feb 18 17:30:58 CET 1999

Alex Buerkle <cbuerkle at bio.indiana.edu> writes:

> In plot() I can get greek symbols into text items without trouble.
> However, some of the same commands don't work as I would expect with
> hist(). See the example below.
> > plot(1:10, 2:11, xlab=expression(paste("scaled", rho)))
> 	---- works as expected, ie. prints the greek rho
> > hist(c(0,0,0,0,4,5,6,6,6,8), xlab=expression(paste("scaled", rho)))
> Error: Object "rho" not found
>         ---- for kicks I tried sigma, it also was not found
> Surprisingly the following worked:
> > hist(c(0,0,0,0,4,5,6,6,6,8), xlab=expression(paste("scaled", pi)))
>         ---- works as expected, ie. prints the greek pi
> Does anyone have any suggestions for how to get such expressions into
> hist()?
> thanks, Alex

First of all, I don't know where people are getting that paste()
construction from. The juxtaposion operator for plotting math is "*",

hist(c(0,0,0,0,4,5,6,6,6,8), xlab=expression("scaled "*rho))

Not that that works either... This is a bug, caused by the eval(xlab)
near the top of hist.default. That line is there for a reason which
escapes me for the moment, but if you completely omit the evaluation,
you get labeling with c(1,2,3,4,...) instead of the variable name, if
you do hist(x).

However, when passing an expression for a label, the eval() mucks
things up by trying to evaluate expressions that only make formal
sense. Replacing it with just plain


seems to work better. (and ditto for "main").

   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list