Skip to content

gap.barplot doesn't support data arrays?

5 messages · Peter Ehlers, Andrew D. Steen, Jim Lemon

#
I am trying to make a barplot with a broken axis using gap.barplot (in the
indispensable plotrix package).  This works well when the data is a vector:
values",main="Barplot with gap")

But when the data is an array (for a bar plot with multiple series) I get an
error and a strange plot with no y-tics and bars stretching downwards, as if
all the values were negative:
gap.barplot(twogrp2,gap=c(8,16),xlab="Index",ytics=c(3,6,17,20),ylab="Group
values",main="Barplot with gap")

Error in rect(xtics[bigones] - halfwidth, botgap, xtics[bigones] +
halfwidth,  : 
  cannot mix zero-length and non-zero-length coordinates

However, the main title and axis labels do appear correctly.

Are data arrays unsupported for gap.barplot, or am I missing something?

Thanks,
Drew Steen
#
On 2011-04-04 06:39, Andrew D. Steen wrote:
Looks like they're not supported, as you could easily see from
the code. But do gapped stacked barplots even make sense? Not
to me.

Still, I think that the plotrix documentation is somewhat
spotty. The help page for gap.barplot indicates that the
input 'y' should be 'data values'; not overly informative.

Peter Ehlers
#
True - gapped stacked bar plots make no sense at all.  I'm working my way up
to a gapped bar plot with series next to each other (and error bars!), what
you'd get if you put a gap in the y-axis of
I'm guessing I can do this if I spend enough time with the axis.break()
function.  But is there an easier way?

--Drew
#
Jim,
That works great.  Thanks much for the quick help.

Cheers,
Drew
#
On 04/04/2011 11:39 PM, Andrew D. Steen wrote:
Aww, gee, you've won me.
Hi Drew,
You are right, as is Peter, gap.barplot doesn't support arrays, only 
vectors (I'll fix the docs). However, it wasn't too hard to whip up a 
rough but perhaps serviceable fix in the attached function. You may need 
to do some mods to the function to get exactly what you want. Try this:

# your twogrp2 left out the high values
twogrp2<-array(twogrp,dim=c(2,10))
source("gap.barp.R")
gap.barp(twogrp2,gap=c(8,16),xlab="Index",ytics=c(3,6,17,20),
  xtics=1:10,ylab="Groupvalues",main="Barplot with gap",col=2:3)

gap.barp returns the modified y values so that you can include the error 
bars.

To paraphrase the immortal P.J. O'Rourke,

"Perhaps R users shouldn't do some things in plots, but they certainly 
can do them"

Jim
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gap.barp.R
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110405/26bd33df/attachment.pl>