[R] breaking the x-axis and having two different x-axis labels

Jim Lemon jim at bitwrit.com.au
Thu Aug 30 13:50:09 CEST 2007


Georg Ehret wrote:
> Dear R community,
>      I have two questions concerning barplots that I struggle to resolve:
> 
> 1) How can I break (interrupt) the x-axis (e.g.: have it display values from
> -100 to -90 and 90 to 100 only)?
>
I think you mean a horizontal barplot with a gap between -90 and 90. 
pyramid.plot (plotrix) doesn't quite do what you want, as the present 
version doesn't allow customized axis labels. The principle is the same 
as that used in gap.barplot, but the maintainer (me) didn't think that 
anyone would want to do this horizontally. If you are stuck I can add a 
feature or two...

However, here's an unbeauteous hack.
heights<-c(sample(-100:-91,5),sample(91:100,5))
barplot(c(heights[1:5]+90,heights[6:10]-90),
  horiz=TRUE,xaxt="n",xlim=c(-10,10))
axis(1,at=seq(-9,9,by=2),
  labels=c(-99,-97,-95,-93,-91,91,93,95,97,99))
axis.break(1,-0.1,style="gap")

> 2) I overlay two horizontal barplots: one with negative values only and one
> with positive values only: I would wish to mark the two datasets separately
> on the x-axis (or some other way). If I use the legend I get a superposed
> result... is there another way?
> 
This sounds like a job for "axis", but I can't really picture what you 
describe. Do you want the negative bars starting from the right and 
going left and the positive ones starting from the left and going right? 
Or a vertical line in the center with the bars going in the usual 
directions?

Jim



More information about the R-help mailing list