[R] Using sub to get captions in barplots

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Tue Sep 30 17:31:52 CEST 2008


> 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]))
> }}

A simple problem: it seems that you have linebreaks in your script in the 
middle of the ylab and sub strings.  Remove these and you should be okay.

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]))
}}

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list