[R] Supercripting text

Kevin Coombes kevin.r.coombes at gmail.com
Mon May 10 21:07:57 CEST 2010


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))), 
list(fn=fn)))
  }
  title
}
# example with footnotes
tt <- ourtitle("stuff", 1:3)
plot(1, 1)
title(tt)
# example without footnotes
plot(1, 1)
title(ourtitle("stuff"))

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.

    Kevin

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