[R] pairs and panel.smooth for two groups

2010-09-08 Thread Marie-Pierre Sylvestre
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@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.


Re: [R] pairs and panel.smooth for two groups

2010-09-08 Thread Greg Snow
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.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Marie-Pierre Sylvestre
 Sent: Wednesday, September 08, 2010 8:03 AM
 To: r-help@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@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.

__
R-help@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.