[R] Constructing arguments for plotmath

Gabor Grothendieck ggrothendieck at gmail.com
Sun Aug 1 18:41:45 CEST 2010


On Sun, Aug 1, 2010 at 11:03 AM, Dennis Fisher <fisher at plessthan.com> wrote:
> Colleagues,
>
> I am encountering difficulty adding formatted text to a graphic.  Specifically, I want to add a superscript in the middle of a text string but I would like to format the text string on the fly.  The commands:
>        plot(1,1)
>        ARG     <- bquote('TEXT'^'\u00ae')
>        mtext(ARG, line=-2, side=1)
> yield the desired output.
>
> However, my goal is to paste together a string, then pass it to mtext.  For example:
>        plot(1,1)
>        PART1   <- 'TEXT'
>        PART2   <- '^'
>        PART3   <- '\u00ae'
>        ARG     <- paste(PART1, PART2, PART3)
>        mtext(bquote(.(ARG)), line=-2, side=1)          ## bquote(ARG) also does not work
> This does not work -- the unprocessed string:
>         TEXT ^ ®
> is printed.
>
> Obviously, I don't understand some aspect of passing arguments to bquote.  Of note, I tried "expression" instead of bquote but I was not able to get the registered sign ('\u00ae') to appear as a superscript.
>
> Any help would be appreciated.

Try this (noting the backquotes around \u00ae since otherwise its not
a valid R name):

x <- "TEXT^`\u00ae`"
plot(0, main =  parse(text = x))



More information about the R-help mailing list