[R] Convert string for expression in plot

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Jan 29 18:54:41 CET 2008



Richard Longland wrote:
> Hi,
> 
> Although I understand how to use expression and paste to add
> superscripts and symbols to my graphs, I have a problem with adding
> superscripts to an existing string.
> 
> For example, I read in the following from a separate file:
> 25Mg(p,g)
> 
> I want to convert that to superscripts etc. (in LaTex format):
> $^{25}$Mg(p,$\gamma$)
> 
> This needs to then be put into a graph title.
> 
> Any ideas? I know that I can just write it in using expression and
> paste, but the title is read in from a separate file.


If you explain what the rules are to use superscript or greek letters 
(why is the p not converted to pi but the g to gamma, etc?), we ca help,
as an example if you read just the number from a file:

#number <- scan(that_file)
# say you read
number <- 25

plot(1:10, main=substitute(phantom()^number * Mg(p, gamma), 
list(number=number)))

See ?plotmath and for automating things like this my article in R News 
might help:
Ligges, U. (2002): R Help Desk: Automation of Mathematical Annotation in 
Plots. R News 2 (3), 32-34.

Best,
Uwe Ligges




> Cheers for the help,
> Richard longland
> 
> ______________________________________________
> 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