[R] Using sub to get captions in barplots

David Afshartous dafshartous at med.miami.edu
Tue Sep 30 17:10:03 CEST 2008


All,

I've been using "sub" (subtitle) instead of "main" such that captions are
below figures produced by xyplot.  This works fine and captions are on a
single line.  However, when I try this for bar plots with error bars
(altering the error.bars function form Crawley's The R Book, see below), the
captions are split on more than 1 line.  Is there a way to get the caption
on a single line? 

Cheers,
David




y.bar.new = c(30, 15)
se.ybar.new = c(2,3)
error.bars(y.bar.new, se.ybar.new, c("Control (n=18)", "CKD (n=18)"))


error.bars<-function(yv,z,nn){
xv<-barplot(yv,ylim=c(0,(max(yv)+max(z))),names=nn,ylab="Total five hour
potassium excretion (mmol)", sub= "Figure 1B: Hour
1-5 potassium excretion")
g=(max(xv)-min(xv))/50
for (i in 1:length(xv)) {
lines(c(xv[i],xv[i]),c(yv[i]+z[i],yv[i]-z[i]))
lines(c(xv[i]-g,xv[i]+g),c(yv[i]+z[i], yv[i]+z[i]))
lines(c(xv[i]-g,xv[i]+g),c(yv[i]-z[i], yv[i]-z[i]))
}}

> sessionInfo()
R version 2.7.1 (2008-06-23)
i386-apple-darwin8.10.1

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods
base     

other attached packages:
[1] lattice_0.17-8 nlme_3.1-89

loaded via a namespace (and not attached):
[1] Matrix_0.999375-11 lme4_0.999375-24   tools_2.7.1



More information about the R-help mailing list