[R] How to properly shade the background panels of an xyplot?

Daniel Kornhauser dkor at northwestern.edu
Thu May 7 23:50:47 CEST 2009


Here is simplified example of what I am having trouble with:
I want to set the gray shade of the background of each panel of a
xyplot with its mean.
My aim is to be able to compare at a glance which panel has the highest mean.
But, in order to achieve this I have to normalize the means between 0 and 1.
The normalization is necessary to stay within the valid range for the
gray() command.
I can’t figure out how to do it :-(

Here is an example where I use max(Oats$yield) (the all around maximum
value) to normalize.
Note that what I am looking for is an expression what would mean
something like this as max(<mean of every panel>)

# Start Example, just copy and paste
data(Oats, package = "MEMSS")
tp1.oats <- xyplot(yield ~ nitro | Variety + Block,
		      data = Oats,
		      panel = function(x, y, subscripts, ...) {	
				# How to normalize my heatmap metric with
				# the value of the panel that has maximum average ?
				# metric = eval(mean(y)/ max(<mean-of-each-panel>)))))
				metric = eval(mean(y)/max(Oats$yield))
				panel.fill(col = gray(metric))
# End Example

Does anybody have any suggestion how I can get max(<mean-of-each-panel>) ?


PS: Deepayan THANKS to your reply to my previous email it was exactly
what I needed.

More information about the R-help mailing list