[R] How can I brake a label in two lines when using expression()?
David Winsemius
dwinsemius at comcast.net
Mon May 7 16:18:50 CEST 2012
On May 7, 2012, at 6:20 AM, Beatriz De Francisco wrote:
>
> I making an xyplot and the y label is too long and needs to be in
> two rows, but when I brake it there is a huge gap between the last
> text string and the expression, and I can't get rid of it. Any ideas?
My first idea would be that you should learn to post "minimal"
examples. Since your question is about how to use plotmath
expressions, you could skip all the data of that with::
xyplot(1~1) # as the "scaffold".
Your question had nothing to do with that data, and it required that
the responder locate the package that had panel.errbars() which you
rather carelessly failed to mention. You can keep those second line
items together using group() but the arrangement on the page is
unsatisfactory since the text newline does not do a linefeed :
ylab=expression("Mean Reapisration Rate
"*group("(", umol.*L^-1*.g *"(AFDM)"^-1,")"))
Try using atop():
ylab=expression(atop("Mean Reapisration Rate",
"("*mu*mol~L^-1*.g~"("*AFDM*")"^-1*")")
)
So this code is my nomination for a minimal solution:
xyplot(1~1, ylab=expression(atop("Mean Reapisration Rate",
"("*mu*mol %.% L^-1 %.% g~"("*AFDM*")"^-1*")")
) )
I also took the liberty of changing the "umol" to a proper micro-mol
with the use of the Greek mu. I also put in proper "cdots" instead of
periods. (So now it meets my personal standards for labeling
proprieties.) If you don't use atop(), the registration of the "bottom
expression" gets messed up, at least in my attempts. One of the known
difficulties with plotmath expressions is the difficulty in getting a
proper line break. atop() solves the two line problem but not the
three line problem.
--
David
>
> Data:
> structure(list(Temp = c(8L, 8L, 8L, 8L, 8L, 8L, 12L, 12L, 12L,
> 12L, 12L, 12L), CO2 = c(380L, 380L, 380L, 750L, 750L, 750L, 380L,
> 380L, 380L, 750L, 750L, 750L), Treat = structure(c(3L, 3L, 3L,
> 4L, 4L, 4L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("12-380", "12-750",
> "8-380", "8-750"), class = "factor"), Week = c(1L, 3L, 8L, 1L,
> 3L, 8L, 1L, 3L, 8L, 1L, 3L, 8L), Mean.Rate = c(2.125909389,
> 1.905870003,
> 1.417687602, 3.110439984, 2.31043989, 1.849232493, 2.546747098,
> 3.290235064, 3.000717599, 2.694901409, 3.852590547, 2.964084249
> ), lower = c(1.846641409, 1.44072624, 1.185304427, 2.56408099,
> 2.02644683, 1.606374443, 2.253928482, 2.759177284, 2.49014747,
> 2.168437604, 3.075977559, 2.438453415), upper = c(2.405177369,
> 2.371013766, 1.650070777, 3.656798978, 2.59443295, 2.092090543,
> 2.839565714, 3.821292844, 3.511287728, 3.221365214, 4.629203535,
> 3.489715083), fTemp = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
> 2L, 2L, 2L, 2L, 2L), .Label = c("8", "12"), class = "factor"),
> fCO2 = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L,
> 2L, 2L), .Label = c("380", "750"), class = "factor"), fTreat =
> structure(c(1L,
> 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L), .Label = c("8-380",
> "8-750", "12-380", "12-750"), class = c("ordered", "factor"
> )), fWeek = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
> 1L, 2L, 3L), .Label = c("1", "3", "8"), class =
> "factor")), .Names = c("Temp",
> "CO2", "Treat", "Week", "Mean.Rate", "lower", "upper", "fTemp",
> "fCO2", "fTreat", "fWeek"), row.names = c(NA, -12L), class =
> "data.frame")
>
> xyplot(cbind(Mean.Rate,lower,upper)~fWeek|fTreat,
> resp.week.mean.rate,
> as.table=TRUE,
> xlab="Week",
> ylab=expression("Mean Reapisration Rate
> (umol."*L^-1*".g (AFDM)"^-1*")"),
> scales=list(alternating=FALSE,
> tick.number=10,
> tck=c(-1,0)),
> layout=c(4,1),
> ylim=1:5,
> auto.key=list(title="Treatment",
> lines=TRUE,
> cex.title=1,
> columns=2),
> panel=function(x, y,...){
> panel.errbars(x,y,make.grid="none",ewidth=0.2,type="p",...)
> panel.loess(x[resp.week.mean.rate
> $Treat=="8-380"],y[resp.week.mean.rate$Treat=="8-380"],span = 5,
> degree = 1,lwd=2,...)
> panel.loess(x[resp.week.mean.rate
> $Treat=="8-750"],y[resp.week.mean.rate$Treat=="8-750"],span = 5,
> degree = 1,lwd=2,...);
> panel.loess(x[resp.week.mean.rate
> $Treat=="12-380"],y[resp.week.mean.rate$Treat=="12-380"],span = 5,
> degree = 1,lwd=2,...);
> panel.loess(x[resp.week.mean.rate
> $Treat=="12-750"],y[resp.week.mean.rate$Treat=="12-750"],span = 5,
> degree = 1,lwd=2,...)
> }
> )
>
> Beatriz de Francisco Mora
> PhD Student
> The Scottish Association for Marine Science
> Scottish Marine Institute
> Oban
> PA37 1QA
> Tel: 06131 559000 (switchboard)
> Fax: 01631559001
> E. beatriz.defrancisco at sams.ac.uk<mailto:beatriz.defrancisco at sams.ac.uk
> >
> http://www.smi.ac.uk/beatriz-de-franciso
>
> The Scottish Association for Marine Science (SAMS) is registered in
> Scotland as a Company Limited by Guarantee (SC009292) and is a
> registered charity (9206). SAMS has an actively trading wholly owned
> subsidiary company: SAMS Research Services Ltd a Limited Company
> (SC224404). All Companies in the group are registered in Scotland
> and share a registered office at Scottish Marine Institute, Oban
> Argyll PA37 1QA. The content of this message may contain personal
> views which are not the views of SAMS unless specifically stated.
> Please note that all email traffic is monitored for purposes of
> security and spam filtering. As such individual emails may be
> examined in more detail.
>
> [[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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list