Thanks Duncan, although that helps me learn something new about lattice plots (I never had played with the as.table argument before), I need something a bit more elegant. I need to generate about 10 plots, each with up to 20 panels. So the panel-by-panel approach is a bit cludgier than I am looking for. I'll look into trellis.focus to see if the light bulb comes on in my head. I'd still appreciate a more efficient way to do this given the number of plots and panels I need. Thanks, Tim
On Tue, Nov 26, 2013 at 2:08 PM, Duncan Mackay <dulca...@bigpond.com> wrote: > Hi > > Try > > 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)), > panel = function(x,y,...){ > > pnl = panel.number() > panel.barchart(x,y,...) > > if (pnl == 6) grid.text("1931=15, 1932=20", 0.5, 0.88, > gp = gpar(cex = 0.8)) > > } > ) > > if you had as.table = TRUE as an argument pnl==1 would apply to the top > panel > > you then have to repeat the line an amend the pnl == 6. > On a panel basis is easier than on a plot basis as the xy coordinates are > easily managed. > > Another way is trellis.focus but possibly a little fiddlier > > Duncan > > Duncan Mackay > Department of Agronomy and Soil Science > University of New England > Armidale NSW 2351 > Email: home: mac...@northnet.com.au > > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On > Behalf Of Tim Sippel > Sent: Wednesday, 27 November 2013 07:08 > To: r-help@r-project.org > Subject: [R] Append text to panels of lattice::barchart() > > 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. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > > [[alternative HTML version deleted]] ______________________________________________ R-help@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.