[R] Splom custom superpanels

Troy S troysocks-twigs at yahoo.com
Tue Aug 12 04:15:41 CEST 2008


R Gurus--

I am trying to adopt this code.  I do not care about colors, but would like
the data in the upper plots jittered.  Here is what I have.  So far, the
lower squares are blank.

Troy

print(splom(foo,
      upper.panel = function(x, y, ...) {panel.splom(jitter(x), jitter(y),
...)},
      lower.panel = function(x, y, ...) {
            #panel.fill(col = brewer.pal(9, "RdBu")[ round(cor(x, y) * 4 +
5)])
          panel.text(mean(x), mean(y), round(cor(x, y,use='p')))
      })) 



Deepayan Sarkar wrote:
> 
> On 8/1/07, Jonathan Williams <williams222 at llnl.gov> wrote:
>> I thought one nice addition to a splom figure would be to have the
>> scatterplots in the upper triangle and a color-coordinated
>> correlation matrix on the bottom.  So I tried my hand at customizing
>> panel.pairs(), and was rebuffed.  Many times.  Four hours of
>> fruitless debugging later, I turn to you for help:
>>
>> panel.pairs(z=teststatfull[,6:12], pscales=0,
>>         panel.subscripts=FALSE, subscripts=,
>>         upper.panel=lattice.getOption("panel.splom"),
>>         lower.panel=function(x1=panel.args$x, y1=panel.args$y,
>>                 panel.args=trellis.panelArgs(),
>> subscripts=1:dim(teststatfull)[1],...){
>>                        
>> panel.fill(col=brewer.pal(9,"RdBu")[round(cor(x1,y1)*4 + 5)])
>>                         panel.text(mean(x1), mean(y1),
>> round(cor(x1,y1),2),
>>                         font=2)})
>>
>> This code is a bit above my level; I stole some tricks from examples
>> I saw elsewhere, and while it looks over-clunky, it works.  Works, at
>> least, in creating the superpanel: you can try it yourself by
>> replacing z with a data frame or matrix of your choice and installing
>> the lattice and RColorBrewer packages.  However, when I try to insert
>> this into the splom function, it all goes to pot.  R scolds me for
>> either missing subscripts, improper subscripts when I try to provide
>> them, or missing data in the panel function, no matter how I define
>> one (or don't).  Can anyone recommend a solution or show me how to
>> make my superpanel function more palatable to splom?
> 
> I haven't figured out how to run your code, even after replacing 'z',
> but I think what you are making things more complicated than they have
> to be:
> 
> library(lattice)
> library(RColorBrewer)
> 
> foo <- mtcars[c(1:6)]
> 
> splom(foo,
>       upper.panel = panel.splom,
>       lower.panel = function(x, y, ...) {
>           panel.fill(col = brewer.pal(9, "RdBu")[ round(cor(x, y) * 4 +
> 5)])
>           panel.text(mean(x), mean(y), round(cor(x, y),2), font=2)
>       })
> 
> Of course, you can, if you really want to, make a custom superpanel
> function to do this:
> 
> my.panel.pairs <- function(..., lower.panel)
> {
>     my.lower.panel <-
>         function(x, y, ...) {
>             panel.fill(col = brewer.pal(9, "RdBu")[ round(cor(x, y) * 4 +
> 5)])
>             panel.text(mean(x), mean(y), round(cor(x, y),2), font=2)
>         }
>     panel.pairs(..., lower.panel = my.lower.panel)
> }
> 
> splom(foo, superpanel = my.panel.pairs)
> 
> -Deepayan
> 
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/Splom-custom-superpanels-tp11950593p18936959.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list