Paul Hewson
2005-Jan-17 09:56 UTC
[R] pairs: altering pch options on upper and lower panel of pairwise scatter plots
Hello, I can't figure out how to use the upper.panel and lower.panel options in pairs to alter the label options for either panel independently of the other. I would like to be able to show the pairwise scatter plots for the data as they are (a vanilla pairs plot?) but separately to be able to label the points according to a factor level. It is easy enough to do this independently, but I can't figure out how to combine the two settings on the same plot. I have enclosed a toy example: Some made up data, e.g. ## make up some multivariate normal data using mvrnorm from MASS ## require(MASS) mu <- c(0,0,0) digma <- matrix(c(0.9,0.5,0.5, 0.5,0.9,0.5, 0.5,0.5,0.9) dummy.data <- mvrnorm(100,mu,sigma) ## ## add a factor ## gender <- as.factor(c(rep("Male",50),rep("Female",50))) I can create two separate pairs plots (upper and lower panel) as follows: ## pairs plot just showing the data pairs(dummy.data, lower.panel = NULL) ## pairs plot where the points are labelled according to a factor pairs(dummy.data, pch = levels(gender), upper.panel = NULL) But I would like to be able to combine the two panels on the same plot. I would be grateful for any advice. I've tried passing several combinations of functions to upper.panel and lower.panel but either they're the wrong function or I'm barking up the wrong tree entirely. Thanks Paul Hewson -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Lecturer in Statistics University of Plymouth Drake Circus Plymouth PL4 8AA Tel ++ 44 1752 232778 Email paul.hewson at plymouth.ac.uk
Uwe Ligges
2005-Jan-18 08:02 UTC
[R] pairs: altering pch options on upper and lower panel of pairwise scatter plots
Paul Hewson wrote:> Hello, > > I can't figure out how to use the upper.panel and lower.panel options in > pairs to alter the label options for either panel independently of the > other. > > I would like to be able to show the pairwise scatter plots for the data > as they are (a vanilla pairs plot?) but separately to be able to label > the points according to a factor level. It is easy enough to do this > independently, but I can't figure out how to combine the two settings on > the same plot. I have enclosed a toy example: > > Some made up data, e.g. > > ## make up some multivariate normal data using mvrnorm from MASS > ## > require(MASS) > mu <- c(0,0,0) > digma <- matrix(c(0.9,0.5,0.5, 0.5,0.9,0.5, 0.5,0.5,0.9) > dummy.data <- mvrnorm(100,mu,sigma) > ## > ## add a factor > ## > gender <- as.factor(c(rep("Male",50),rep("Female",50))) > > > > > I can create two separate pairs plots (upper and lower panel) as > follows: > > ## pairs plot just showing the data > > pairs(dummy.data, lower.panel = NULL) > > ## pairs plot where the points are labelled according to a factor > > pairs(dummy.data, pch = levels(gender), upper.panel = NULL) > > > But I would like to be able to combine the two panels on the same plot. > I would be grateful for any advice. I've tried passing several > combinations of functions to upper.panel and lower.panel but either > they're the wrong function or I'm barking up the wrong tree entirely.pairs(dummy.data, lower.panel = function(x, y) points(x, y, pch = levels(gender))) Uwe Ligges> Thanks > > Paul Hewson > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > Lecturer in Statistics > University of Plymouth > Drake Circus > Plymouth PL4 8AA > > Tel ++ 44 1752 232778 > Email paul.hewson at plymouth.ac.uk > > ______________________________________________ > 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