[R] percentage sign in expression

David Winsemius dwinsemius at comcast.net
Tue Aug 24 16:09:14 CEST 2010


On Aug 24, 2010, at 9:37 AM, e-letter wrote:

> Readers,
>
> According to the documentation for the function 'plotmath' there is no
> apparent possibility to add the percent sign (%) to a plot function,

Where did you see an assertion made???

> e.g.
>
> plot(a[,1]~b[,2],ylab=expression(x~%),xlab=expression(z))


>
> How to achieve this please?

Read the plotmath helo page more carefully. The section immediatedly  
below the plotmath expressions points you to the use of the symbol()  
expression-function and to the points help page where generation of  
the available glyphs proceeds according to the advice on help(plotmath):

 > TestChars <- function(sign=1, font=1, ...)
+ {
+    if(font == 5) { sign <- 1; r <- c(32:126, 160:254)
+    } else if (l10n_info()$MBCS) r <- 32:126 else r <- 32:255
+    if (sign == -1) r <- c(32:126, 160:255)
+    par(pty="s")
+    plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="",
+         xaxs="i", yaxs="i")
+    grid(17, 17, lty=1)
+    for(i in r) try(points(i%%16, i%/%16, pch=sign*i, font=font,...))
+ }
 > TestChars(font=5)

Notice that the "%" sign is three characters to the right (i.e.  
higher) of the "forall" symbol that is produced by the example code  
they offer. (The numbering proceeds from bottom up which confused me  
at first.)

So:

plot(1, ylab=expression(symbol("\045") ))

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list