[R] Superscript in legend without using expression function

Gabor Grothendieck ggrothendieck at gmail.com
Mon Feb 9 01:08:56 CET 2015


On Sat, Feb 7, 2015 at 4:57 PM, jgui001 <j.guilbert at auckland.ac.nz> wrote:
> I am plotting three sets of data on a single graph, and doing around 100+
> graphs.
> I can use the expression function to superscript the 2 but that seems to
> force me to manually put in the R squared values. Is there away around this?
>
> This code will show what it should look like this but with the 2
> superscripted
>
> r1<-c(0.59,0.9,0.6)
> plot(1:6)
> legend("topleft",
> legend=c(paste("G1 r=",r1[1]), paste("G2 r=",r1[2]), paste("G3 r=",r1[3])))

Replace the legend statement with:

leg <- as.list(parse(text = sprintf("G%d~r^2=%.2f", 1:3, r1)))
legend("topleft", legend = leg)



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list