[R] panel function with barchart (lattice)

From: Drew <drewbrewit_at_yahoo.com>
Date: Wed 25 Jan 2006 - 18:35:23 EST


Folks at R help,

I can't quite get the panel function to work the way I want within barchart.
I guess I'm still not understanding how to piece together multiple panel
arguments, especially when "groups" is specified.

Example: I want to be able to add the value of "yield" to each section of
each bar in this graph:

barchart(yield ~ variety | site, data = barley,

	groups = year,
	layout = c(1,6),
	stack=TRUE,
	ylab = "Barley Yield (bushels/acre)"

)

To do this, I add my panel function:

barchart(yield ~ variety | site, data = barley,

	groups = year,
	layout = c(1,6),
	stack=TRUE,
	ylab = "Barley Yield (bushels/acre)",

	panel = function(x,y,subscripts,groups,...){
		panel.barchart(x,y,...)
		ltext(x = x, y = y, label =
round(barley$yield[subscripts],1), cex=.8)
	}

)

Then I get the values to print on each bar (which is what I want) but the
bars no longer stack to appropriate height, and I cannot get the subsections
of each bar to be a different color. I've tried numerous variations of
panel.barchart, panel.superpose, etc. using examples from ?xyplot, but
nothing quite works or I get an error message.

Any help would be appreciated.

~Nick



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jan 25 18:44:39 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:10 EST