Mike Townsley
2006-Sep-13 08:20 UTC
[R] forcing levelplot to use relative cuts (ie cuts for each panel)
Dear guRus, I'm having trouble producing a levelplot with relative cuts for each panel (my data has large differences in scales, so I want to use quantiles for each panel). My attempts to change the 'at' argument in panel.levelplot function have not met with success. Below is a toy example. xy <- expand.grid(x = 1:3, y = 1:3) aaa <- rbind(cbind(xy, z = 1:9, site = rep('A', 9)), cbind(xy, z = (1:9)/10, site = rep('B', 9)), cbind(xy, z = (1:9)*10, site = rep('C', 9))) aaa library(lattice) levelplot(z~x+y|site, data = aaa) # using absolute cuts # now, attempt relative cuts levelplot(z~x+y|site, data = aaa, panel = function(...) { panel.levelplot(at = quantile(z),...) }) I get the following message: Error in panel.levelplot(at = quantile(z), ...) : formal argument "at" matched by multiple actual arguments My idea was to determine the cut points each time the panel function is called (ie each subset of the data), but I guess this was the wrong thing to do. Can someone point out what I'm missing? Thanks in advance, MT ------------------------------------------------------------ Dr Michael Townsley Senior Research Fellow Jill Dando Institute of Crime Science University College London Second Floor, Brook House London, WC1E 7HN Phone: 020 7679 0820 Fax: 020 7679 0828 Email: m.townsley at ucl.ac.uk
Deepayan Sarkar
2006-Sep-13 22:59 UTC
[R] forcing levelplot to use relative cuts (ie cuts for each panel)
On 9/13/06, Mike Townsley <uctcmkt at ucl.ac.uk> wrote:> Dear guRus, > > I'm having trouble producing a levelplot with relative cuts for each > panel (my data has large differences in scales, so I want to use > quantiles for each panel). > > My attempts to change the 'at' argument in panel.levelplot function > have not met with success. > > Below is a toy example. > > xy <- expand.grid(x = 1:3, y = 1:3) > > aaa <- rbind(cbind(xy, z = 1:9, site = rep('A', 9)), > cbind(xy, z = (1:9)/10, site = rep('B', 9)), > cbind(xy, z = (1:9)*10, site = rep('C', 9))) > > aaa > > library(lattice) > levelplot(z~x+y|site, data = aaa) # using absolute cuts > > # now, attempt relative cuts > > levelplot(z~x+y|site, data = aaa, panel = function(...) { > panel.levelplot(at = quantile(z),...) }) > > I get the following message: > Error in panel.levelplot(at = quantile(z), ...) : > formal argument "at" matched by multiple actual arguments > > My idea was to determine the cut points each time the panel function > is called (ie each subset of the data), but I guess this was the > wrong thing to do. Can someone point out what I'm missing?Mostly that you have to catch the arguments you want to use/replace, e.g. levelplot(z~x+y|site, data = aaa, panel = function(..., z, at) { panel.levelplot(..., z = z, at = quantile(z)) }) This won't actually give you want, you will need: levelplot(z~x+y|site, data = aaa, panel = function(..., z, subscripts, at) { panel.levelplot(..., z = z, subscripts = subscripts, at quantile(z[subscripts])) }) ?panel.levelplot should explain why. Deepayan