[R] Inserting superscripts in free-format text line

William Dunlap wdunlap at tibco.com
Mon Aug 20 21:27:01 CEST 2012


paste() is ok, but it must be enclosed in expression(),
just like the case that worked.

plot(-15:15,15:-15)
text(x=5, y=4.5, expression(test^1) )
text(x=1, y=11, expression(paste("This is a ", test^1, " of the Emergency Broadcast System.")))

plotmath only works on expressions, not on the strings
that a call to paste would produce.


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of David Winsemius
> Sent: Monday, August 20, 2012 12:15 PM
> To: Brian Kriegler
> Cc: r-help at r-project.org
> Subject: Re: [R] Inserting superscripts in free-format text line
> 
> 
> On Aug 20, 2012, at 11:35 AM, Brian Kriegler wrote:
> 
> > I would like to insert a superscript in a body of text (e.g., a
> > title or axis label), where the superscript is not necessarily at
> > the end of the text.  For example, suppose a title read, "This is a
> > Test^1 of the Emergency Broadcast System" where there is a
> > superscript 1 after the word Test.
> >
> > As a starting point for what I'm trying to do, the following shows a
> > superscript:
> > x=10
> > plot(x)
> > text(x=1, y=12, expression("test"^1)
> 
> Not on my device. No closing paren.
> 
> Why not:
> 
> plot(1:10)
> text(x=5, y=4.5, expression(test^1) )
> 
> You do not need quotes in plotmath expressions unless they are
> reserved plotmath function names. People reach for paste() in far too
> many situations.
> 
> >
> > But, the following does not show a superscript:
> > x=10
> > plot(x)
> > text(x=1, y=11, paste("This is a", expression("test"^1), "of the
> > Emergency Broadcast System.")
> 
> And why not:
> 
>   expression(This~is~a~test^1~of~the~Emergency~Broadcast~System.)
> 
> >
> --
> 
> David Winsemius, MD
> Alameda, CA, USA
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list