Michael Kubovy
2007-Feb-09 22:26 UTC
[R] How to add the variable name to a qqplot or densityplot in the diagonal of an splom?
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?
splom(szw[, n], pscales = 0,
diag.panel = function(x, ...){
panel.qqmathline(x, ...)
panel.qqmath(x, ...)
},
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/
Deepayan Sarkar
2007-Feb-10 16:34 UTC
[R] How to add the variable name to a qqplot or densityplot in the diagonal of an splom?
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. >