[R] pairs and panel.smooth for two groups

Greg Snow Greg.Snow at imail.org
Wed Sep 8 19:30:04 CEST 2010


This is fairly simple using lattice graphics:

USJudgeRatings <- USJudgeRatings[,1:4]
USJudgeRatings$group <- factor(c(rep(1, 22), rep(0, 21)))

library(lattice)
splom( ~USJudgeRatings[,1:4], groups=group, data=USJudgeRatings,
	type=c('p','smooth'))


The ggplot2 package probably makes this easy as well (but I am still learning that).

If you really need to use the pairs function then you will need to create your own panel function (which could call panel.smooth).

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Marie-Pierre Sylvestre
> Sent: Wednesday, September 08, 2010 8:03 AM
> To: r-help at r-project.org
> Subject: [R] pairs and panel.smooth for two groups
> 
> Hi,
> I have modified the USJudgeRatings data (available in R)  to
> illustrate my question.
> 
> # Use the first 4 variables of USJudgeRatings and add a group variable
> with two levels
> USJudgeRatings <- USJudgeRatings[,1:4]
> USJudgeRatings$group <- factor(c(rep(1, 22), rep(0, 21)))
> 
> # I can draw a pairs graph where members of each group are drawn in
> different colors:
> 
> pairs(USJudgeRatings[,1:4], col = c(2,3)[USJudgeRatings$group], pch =
> c(21,3)[USJudgeRatings$group])
> 
> # I would also like to add a smooth line to each subplot like
> pairs(USJudgeRatings[,1:4], panel=panel.smooth)
> 
> # but I want the smooth to be done for each of the group, i.e. I want
> two smooths per subplot.
> 
> # this creates only one smooth
> pairs(USJudgeRatings[,1:4], col = c(2,3)[USJudgeRatings$group], pch =
> c(21,3)[USJudgeRatings$group], panel = panel.smooth)
> 
> # I understand that panel.smooth is a function that is called for each
> subplot. I don't know how to tell it to do a smooth for each of my
> group in each of the subplot.
> 
> Any help would be appreciated!
> 
> Best,
> 
> Marie-Pierre
> 
> ______________________________________________
> R-help at r-project.org 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