A non-text attachment was scrubbed... Name: not available Type: text Size: 478 bytes Desc: not available Url : https://stat.ethz.ch/pipermail/r-help/attachments/19971103/ae2f1119/attachment.pl
Martin Maechler
1997-Nov-03 15:02 UTC
R-beta: math in legends: strwidth() will have to be enhanced
>>>>> "Jim" == Jim Lindsey <jlindsey at luc.ac.be> writes:Jim> Expression is great for math on the axes of plots. However, it Jim> does not appear to work in legend. Any chance of including this? The only thing which must be enhanced is the strwidth(..) function. Here is a **very** cheap workaround for `strwidth' which makes legend "work" with expressions: strwidth <- function(s, units="user", cex=NULL) { fudge <- 1 if(!is.character(s)) { if(is.expression(s)) { ##-- Internal 'strwidth' should be enhanced for expressions !!! ##-- The following is a CHEAP workaround ! ns <- length(se <- s); s <- character(ns) for(i in 1:ns) s[i] <- paste(deparse(se[i]),collapse="") } else stop("`s' must be `character' or `expression'") fudge <- 0.6 } fudge*.Internal(strwidth(s, pmatch(units, c("user", "figure", "inches")), cex)) } E.g., the following example now works for me: ex12 <- expression(bar(x) == sum(over(x[i], n), i==1, n), hat(x) == median(x[i], i==1,n)) plot(1:10,1:10) legend(7,4, ex12, y.intersp = 2) Martin Maechler <maechler at stat.math.ethz.ch> <>< Seminar fuer Statistik, SOL G1 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1086 http://www.stat.math.ethz.ch/~maechler/ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=