[R] Bar chart: break long bars

Jim Lemon jim at bitwrit.com.au
Tue Oct 25 14:41:10 CEST 2011


On 10/25/2011 09:27 PM, Florian Weiler wrote:
> Dear all,
>
> I have a problem with my stacked bar charts. I have one very long bar, hence
> I would like to break the x-axis at a certain point so that the shorter bars
> can be seen better.
>
> Here is a cooked up example:
> library(lattice)
> group<- rep(1:3,10)
> x<- runif(30, 0, 100)
> y<- runif(30, 0, 100)
> x[5]<-500
> z<- rep(seq(1:10),3)
> z<- z[order(z)]
> frame<- data.frame(group,x,y,z)
> barchart(z ~ y +x | group, data=frame, stack=T,
>           col=c("white","grey"),
>           xlim=c(0,600))
>
> If you run this code, there will be one very long bar in the chart on the
> lower right-hand side. All other bars are by construction shorter than 200.
> How could I now break the x-axis somewhere around 200 and then continue at,
> say, 500? Sorry, I was just unable to figure that out myself.
> And given that I'm already posting something, I have another little
> question. How could I, in the same graph, turn off that little orange
> indicator for the group appearing in the strip?
>
Hi Florian,
Have a look at the gap.barplot function (plotrix).

Jim



More information about the R-help mailing list