[R] Bar width and labels in barchart

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Jan 24 17:56:12 CET 2008


On 1/23/08, Spilak,Jacqueline [Edm] <Jacqueline.Spilak at ec.gc.ca> wrote:
> Hi everyone
> I am using barchart to make my graphs.  Here is my code.
>
> barchart(percent_below ~ factor(Year)| factor(Season,
> levels=unique(Season)),
>       data= .season_occurrence, origin = 0, layout = c(4, 1),
> scales=list(tick.number=ticknum,labels=NULL), ylim=c(0, ymax),
>         group = factor(Year), xlab= "Year", auto.key = list(points =
> FALSE, rectangles = TRUE,space="right",size=2,cex=0.8),
>         upper_2007 = c(upper_limit_winter, upper_limit_spring,
> upper_limit_summer, upper_limit_autumn),
>         par.settings = list(superpose.polygon =
> list(col=c(color1,color2,color3,color4,color5,color6,color7,color8))),
>         lower_2007 = c(lower_limit_winter, lower_limit_spring,
> lower_limit_summer, lower_limit_autumn),
>       panel = function(..., upper_2007,lower_2007) {
>             panel.abline(h = upper_2007[packet.number()])
>                 panel.abline(h = lower_2007[packet.number()])
>             panel.barchart(...)
>          })
>
> This code gives me a graph with four panels, one for each season, and
> then the percent_below is shown per year in each panel.  I wanted each
> year to have a color associated with it so I added group = factor(Year)
> this worked and gave me what I wanted, however now the bars are very
> skinny and it is hard to distinguish the colors.  How do I make them
> wider?  My other question is that on the x-axis it list all years
> (2000-2007, inclusively) for each panel and they are squished and
> non-legable, can I get rid of them?  They are not necessary as I have
> the years color coded with the legend at the side.

Does having stack=TRUE help?

If you have year as the x-variable, barchart will try to label them.
You could control the labels using 'scales', but I think having some
other variable as the x-variable might be the better solution. We need
a (minimal) reproducible example to give more definite advice.

-Deepayan



More information about the R-help mailing list