[R] Append text to panels of lattice::barchart()

p_connolly p_connolly at slingshot.co.nz
Tue Nov 26 22:58:32 CET 2013


On 2013-11-27 10:07, Tim Sippel wrote:
> I could use a little help writing a panel function to append text to 
> each
> panel of a lattice::barchart().  Below is a modified version of the 
> barley
> dataset to illustrate.
> 
> data(barley)
> # add a new variable called samp.size
> barley$samp.size<-round(runif(n=nrow(barley), min=0, max=50),0)
> # Below is a barchart plot for this example
> barchart(yield ~ variety | site, data = barley,
>          groups = year, layout = c(1,6), stack = TRUE,
>          auto.key = list(space = "right"),
>          ylab = "Barley Yield (bushels/acre)",
>          scales = list(x = list(rot = 45)))
> # I need to add to each panel the sum of samp.size by the groups 
> variable
> (year) for that panel.
> # So the text appended to the top panel (Waseca) might say "1931=15,
> 1932=20", and same for each subsequent panel.

All you need is to modify the levels associated with the site factor.  
Here's  a trivial addition to give you the idea:

levels(barley$site) <- paste(levels(barley$site), LETTERS[1:6])

Then the same call you used will work.  Of course, you'll need to do a 
bit more than LETTERS[1:6] but I'm sure you know how to do that.

HTH


> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.



More information about the R-help mailing list