[R] How to add the variable name to a qqplot or densityplot in the diagonal of an splom?

Deepayan Sarkar deepayan.sarkar at gmail.com
Sat Feb 10 17:34:02 CET 2007


On 2/9/07, Michael Kubovy <kubovy at virginia.edu> wrote:
> splom() doesn't complain here, but writes no names in the diagonal
> boxes. What am I missing?
> I believe that I need to add something like grid.text(x, ...) to the
> diagonal panel, but I don't know how to get it cycle through the
> column labels. And should
>      varname.col = 'blue', varname.cex = 1
> be inside the diag.panel() function?

These are passed on to panel.pairs, which in turn passes these on to
diag.panel. Whether your diag.panel uses it or not is up to you (see
below for an example that does).

>
> splom(szw[, n], pscales = 0,

<obligatory rant>
Simply using a built in data set, like 'iris', instead of undefined
variables 'szw' and 'n' would have made this a reproducible example
</obligatory rant>

>      diag.panel = function(x, ...){
>          panel.qqmathline(x, ...)
>          panel.qqmath(x, ...)
>      },

change this to

     diag.panel = function(x, ...){
         panel.qqmathline(x, ...)
         panel.qqmath(x, ...)
         diag.panel.splom(x = x, ...)
     },

You could also use grid.text of course, but you need to capture the
'varname' argument that panel.pairs passes on to diag.panel.splom.


>      lower.panel = function(x, y, ...){
>          panel.xyplot(x, y, ..., col = 'lightblue')
>          panel.loess(x, y, ..., col = 'red')
>      },
>      upper.panel = function(x, y, ...){
>          panel.abline(lm(y~x),...)
>          grid.text(round(cor(x, y, use = 'pairwise.complete.obs'), 2),
>              x = unit(1, 'mm'),
>              y = unit(1, 'npc') - unit(1, 'mm'),
>              just = c('left', 'top'),
>              gp = gpar(fontsize = 10))
>      },
>      varname.col = 'blue', varname.cex = 1
> )
>
>
> _____________________________
> Professor Michael Kubovy
> University of Virginia
> Department of Psychology
> USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
> Parcels:    Room 102        Gilmer Hall
>          McCormick Road    Charlottesville, VA 22903
> Office:    B011    +1-434-982-4729
> Lab:        B019    +1-434-982-4751
> Fax:        +1-434-982-4766
> WWW:    http://www.people.virginia.edu/~mk9y/
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list