Beatriz De Francisco
2012-May-03 11:20 UTC
[R] braking a label in two lines when using expression()
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? 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@sams.ac.uk<mailto:beatriz.defrancisco@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]]
Your code did not run on my computer, however the "atop" function should do what you are looking for I guess. This is more or less your axis, only changed a bit in your formula, think it looks better this way: e.g. par(mar=c(5,7,.5,.5), las=1, adj=.5, cex.lab=1.5) plot(1, type="n" , xlab="Week" , ylab=expression(atop("Mean Respisration Rate", umol%.%L^-1%.%g~(AFDM)^-1) )) -- View this message in context: http://r.789695.n4.nabble.com/braking-a-label-in-two-lines-when-using-expression-tp4605716p4606414.html Sent from the R help mailing list archive at Nabble.com.