[R] adding lines to a barchart
Deepayan Sarkar
deepayan.sarkar at gmail.com
Wed Dec 19 21:31:59 CET 2007
On 12/19/07, Spilak,Jacqueline [Edm] <Jacqueline.Spilak at ec.gc.ca> wrote:
> Hi all
> I can't find what I am looking for so I am asking here. I have a
> dataset that looks something like this.
>
> Year season percent_below
> 2000 Winter 6.9179870
> 2000 Spring 1.6829436
> 2000 Summer 1.8463501
> 2000 Autumn 3.8184993
> 2001 Winter 2.8832806
> 2001 Spring 2.5870511
> 2001 Summer 0.0000000
> 2001 Autumn 4.7248240
> 2002 Winter 4.4532238
> 2002 Spring 3.7468846
> 2002 Summer 1.0784311
> 2002 Autumn 3.7061533
>
> I have plotted this nicely using
> barchart(percent_below ~ factor(Season, levels=Season), data= dataset1,
> group=Year)
> This gives me a barplot by season with each year shown in that season.
> Now the tricky part. My data is from 2000 to 2007 and 2007 is an
> important year. I have an upper and lower limit for percent_below for
> 2007 for each season. I would like to add the upper and lower limit of
> 2007 as a black line to each season. The upper and lower limit will be
> different for each season. This is being done so for a comparison so I
> need it done this way.
I would suggest a slightly different format. Here's an example with
one set of limits; you can add another set similarly. If you really
want a single panel, you could use panel.segments().
barchart(percent_below ~ factor(Year) | factor(season, levels=unique(season)),
data= dataset1, origin = 0, layout = c(4, 1),
upper_2007 = c(6, 4, 5, 3),
panel = function(..., upper_2007) {
panel.abline(h = upper_2007[packet.number()])
panel.barchart(...)
})
-Deepayan
More information about the R-help
mailing list