[R] How do I wrap a long mixed text/math expression in an axis label?

Cheryl Squair squair at hawaii.edu
Mon Oct 19 11:28:11 CEST 2009


I would like to wrap a y-axis label onto two lines. My label is an expression
containing both text and math symbols. I have looked at plotmath,
strsplit(), strwrap(), deparse(), do.call(), substitute() and bquote().
Based on previous posts, I can get plain text to wrap. However, when I try
these methods on my label, the exact string is returned, rather than
evaluating the math symbols.

My starting point:

x<-c(1:10)
y<-seq(5,50,5)
par(mar=c(6,6,6,1),cex.lab=1.3,cex.axis=1.2)
plot(x,y, xlab=NA, ylab=expression(paste("Saturating Irradiance, ",E[k],",
",mu,"mol photons ", m^-1," ", s^-1)))

An unsuccessful example:

plot(x,y, xlab=NA, ylab=strwrap(expression(paste("Saturating Irradiance,
",E[k],", ",mu,"mol photons ", m^-1," ", s^-1)), width=26))

I've tried so many iterations that I have thoroughly confused myself! I
would appreciate any input on how to get the expression to wrap on two (or
more, if I had a really long label) lines. I am using R version 2.9.2
(2009-08-24) on a Mac running OS X 10.5.8.

Many thanks for your time.
-- 
View this message in context: http://www.nabble.com/How-do-I-wrap-a-long-mixed-text-math-expression-in-an-axis-label--tp25955461p25955461.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list