Skip to content

adding lines to a barchart

4 messages · Spilak,Jacqueline [Edm], Deepayan Sarkar

#
On 12/19/07, Spilak,Jacqueline [Edm] <Jacqueline.Spilak at ec.gc.ca> wrote:
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
1 day later
#
Thanks Deepayan, this helped a lot and gave me exactly what I wanted
however I want a few changes and am not sure how to do them.  In each
panel the bars for the years are the same color with the bottom axis
(the x-axis) labelled with the years.  I would like each year to have a
specific color with a legend for it at the side, is this possible?
And my other question is that there seems to be a gap between where the
bars start and the x-axis, it is kinda funny looking so is there anyway
to change this?
Thanks for all the help
On 12/19/07, Spilak,Jacqueline [Edm] <Jacqueline.Spilak at ec.gc.ca> wrote:
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
#
On 12/21/07, Spilak,Jacqueline [Edm] <Jacqueline.Spilak at ec.gc.ca> wrote:
Sure, just use Year as a grouping variable as well.

barchart(percent_below ~ factor(Year) | factor(season, levels=unique(season)),
         data = dataset1, layout = c(4, 1),
         groups = factor(Year),
         auto.key = list(points = FALSE, rectangles = TRUE),
         stack = TRUE,
         upper_2007 = c(6, 4, 5, 3),
         panel = function(..., upper_2007) {
             panel.abline(h = upper_2007[packet.number()])
             panel.barchart(...)
         })
What exactly do you want to happen? I don't think a bar chart is an
appropriate visualization unless the lengths of the bars mean
something. If it does, and you just want to get rid of the space below
zero, the easiest way is to set an explicit ylim=c(0, 7) or something.
If the lengths don't really mean anything, you should consider using
dotplot() instead.

-Deepayan