Re: [R] barchart but with boxes

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Mon, 07 Jun 2010 21:27:12 +1000

On 06/07/2010 04:53 PM, Daisy Englert Duursma wrote:
> Hello r-help.
>
> I have been working on making a graph and have several solutions but
> they are tedious at best.
>
> Here is an example dataset:
>
> catg<-(c(1,2,3,2,4,3,2,1,4,3,1))
> min<-(c(1,2,3,3,4,5,6,6,3,2,1))
> max<-(c(10,6,8,6,7,3,10,9,10,8,9))
> cbind(min,max,catg)
>
> What I want to create is a basically a bar chart, but I define the
> min (min) and max (max) for the bars.
> These bars are separated into three categories (catg). Within each
> category the bars are allowed to overlap. I set the bars to have a
> transparent color so that I can see agreement of the items within a
> category based on the darkness of color.
>
> One method I came up with, is to use ggplot2 and geom_tile but then I
> have to give x,y coordinates for every corner of every box.
> Considering the size of my real datasets, and not this little example
> dataset, this seems annoying.
>
> I could even just graph lines with the defined min and max. With that
> I could make the lines thick and achieve the effect I am looking for.
>
Hi Daisy,
How about this?

offset<-c(-0.1,-0.1,-0.1,0,-0.1,0,0.1,0,0,0.1,0.1) plot(0,xlim=c(0.5,4.5),ylim=c(0,10),type="n") segments(catg+offset,min,catg+offset,max,lwd=5,col=3)

You can program a function to calculate the offsets if you want to do lots of these.

Jim



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 07 Jun 2010 - 11:28:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 Jun 2010 - 12:00:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive