[R] How do I wrap a long mixed text/math expression in an axis label?
murdoch at stats.uwo.ca
Mon Oct 19 15:03:46 CEST 2009
On 10/19/2009 5:28 AM, Cheryl Squair wrote:
> 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.
You can't really get plotmath to wrap, as far as I know, but you can
manually split a label to go onto two lines using atop. For example,
with your setup I don't think your margins are big enough, but the
following seems to work:
plot(x,y, xlab=NA, ylab=expression(atop(paste("Saturating Irradiance, ",
E[k], ",",mu,"\nmol"), paste(" photons ", m^-1," ", s^-1))))
> My starting point:
> 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.
More information about the R-help