[R] Supercripting text

Shang Gao sgao at econone.com
Mon May 10 21:14:47 CEST 2010

I tried writing that function before, but the expression() command is not preserved when we incorporate it into a function(). The first example you gave me, if run in R, produced a title that reads "title" instead of "stuff". It seems that in this case the expression() can't read the character string in the argument specified in the function() command.

-----Original Message-----
From: Kevin Coombes [mailto:kevin.r.coombes at gmail.com] 
Sent: Monday, May 10, 2010 12:08 PM
To: Shang Gao
Cc: r-help at r-project.org
Subject: Re: [R] Supercripting text

You probably want to write your own titling function to add 
superscripts.  The following code will serve as a reasonable starting point:

# make the title expression
ourtitle <- function(title, footnotes=NULL) {
  if (length(footnotes) > 0) {
    fn <- paste(footnotes, collapse=' ')
    title <- eval(substitute(expression(bold(paste(title, ""^fn))), 
# example with footnotes
tt <- ourtitle("stuff", 1:3)
plot(1, 1)
# example without footnotes
plot(1, 1)

Note that the only way I could make this work was to combine the 
footnote list before calling the eval-substitute-expression code; I 
cannot get it to work by applying things ot a list.


Shang Gao wrote:
> Dear R users,
> I recently developed a plotting function in R and introduced it to my coworkers. The function is designed to make plotting easier and more efficient, which will in turn be more cost-effective for the company. The reviews for the function have been positive thus far, except for one issue -- addition of superscripts to the title. We need superscipts in the titles sometimes to highlight footnotes which appear at the bottom of the plots.
> The syntax for supersciprts, however, is rather cumbersome, especially in titles since it needs to be bolded. So far the only way of superscripting is to use the expression() function. But to go about formatting the text such that it appears bolded as a title in my plots, I would have to type in the command
>> text(expression(bold(paste("text for title",""^1)))....)
> In some cases, the plot would require 3 footnotes to be shown, and the code would be
>> text(expression(bold(paste("text for title",""^1, " "^2, " "^3))).....)
> Most of my coworkers are still in the process of picking up R, some have never used R before. The above commands may be a little too much for them to handle.
> Is there an easier way of superscripting texts in R? It would be great if any of you know of alternative ways other than using the expression() function.
> I greatly appreciate your help.
> Thank you.
> Sincerely,
> Shang
> 	[[alternative HTML version deleted]]
> ______________________________________________
> 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