[R] multiple lowess line in one plot

2006-01-04 Thread Dean Sonneborn
I'm using this code to plot a smoothed line.  These two columns of data 
really represent 4 groups and I'd like to plot a separate line for each 
group but have them all in the same plot. The R-Docs for lowess do not 
seem to indicate some type of GROUPS=var_name option. What would be 
the syntax for this?

plot(AWGT ~ lipid )
lines(lowess(lipid , AWGT, f=.8))


-- 
Dean Sonneborn, MS
Programmer Analyst
Department of Public Health Sciences
University of California, Davis
(530) 754-9516

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


Re: [R] multiple lowess line in one plot

2006-01-04 Thread Austin, Matt
Try using the panel.plsmo function in Dr. Harrell's Hmisc package.

xyplot(AWGT ~ lipid, groups = var_name, panel=panel.plsmo)

--Matt

Matt Austin

Statistician
Amgen, Inc.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Dean Sonneborn
Sent: Wednesday, January 04, 2006 8:54 AM
To: r-help@stat.math.ethz.ch
Subject: [R] multiple lowess line in one plot


I'm using this code to plot a smoothed line.  These two columns of data 
really represent 4 groups and I'd like to plot a separate line for each 
group but have them all in the same plot. The R-Docs for lowess do not 
seem to indicate some type of GROUPS=var_name option. What would be 
the syntax for this?

plot(AWGT ~ lipid )
lines(lowess(lipid , AWGT, f=.8))


-- 
Dean Sonneborn, MS
Programmer Analyst
Department of Public Health Sciences
University of California, Davis
(530) 754-9516

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

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


Re: [R] multiple lowess line in one plot

2006-01-04 Thread MMcIntosh
## Copy and paste this into R.
x1-rbinom(dim(cars)[1],2,.5)
plot(cars,main=lowess(modified cars),col=x1+1)
for(i in unique(x1)) lines(lowess(cars[x1==i,]),col=i+1)

This might help...

Matthew McIntosh



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Dean Sonneborn
Sent: Wednesday, January 04, 2006 10:54 AM
To: r-help@stat.math.ethz.ch
Subject: [R] multiple lowess line in one plot

I'm using this code to plot a smoothed line.  These two columns of data 
really represent 4 groups and I'd like to plot a separate line for each 
group but have them all in the same plot. The R-Docs for lowess do not 
seem to indicate some type of GROUPS=var_name option. What would be 
the syntax for this?

plot(AWGT ~ lipid )
lines(lowess(lipid , AWGT, f=.8))


-- 
Dean Sonneborn, MS
Programmer Analyst
Department of Public Health Sciences
University of California, Davis
(530) 754-9516

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

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


Re: [R] multiple lowess line in one plot

2006-01-04 Thread Gregory Snow
Here is one approach using lattice (trellis) graphics:

tmp.state - data.frame( Frost=state.x77[,'Frost'], 
Murder=state.x77[,'Murder'], 
Region=state.region)

library(lattice)
trellis.par.set(col.whitebg())
xyplot( Murder ~ Frost, groups=Region, data=tmp.state,
panel.groups=function(...){panel.loess(...);panel.xyplot(...)}
,span=.8)


Just substitute in your variables and variable names.

Hope this helps,



-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Dean Sonneborn
 Sent: Wednesday, January 04, 2006 9:54 AM
 To: r-help@stat.math.ethz.ch
 Subject: [R] multiple lowess line in one plot
 
 I'm using this code to plot a smoothed line.  These two 
 columns of data really represent 4 groups and I'd like to 
 plot a separate line for each group but have them all in the 
 same plot. The R-Docs for lowess do not seem to indicate some 
 type of GROUPS=var_name option. What would be the syntax for this?
 
 plot(AWGT ~ lipid )
 lines(lowess(lipid , AWGT, f=.8))
 
 
 --
 Dean Sonneborn, MS
 Programmer Analyst
 Department of Public Health Sciences
 University of California, Davis
 (530) 754-9516
 
 __
 R-help@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


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


Re: [R] multiple lowess line in one plot

2006-01-04 Thread Paul Johnson
It appears to me lowess has no subset or strata option. The
brute-force way (which my students like best) is just to create 4
columns, one for each group (with unstack or such) and then run one
lines(lowess()) command for each one.

I think there is a bit more art in using by, which will create subsets
on the fly for you.

Here is a self contained example that I just worked out to illustrate.
grp is the grouping factor, x and y are just illustrative data. The by
function creates the data subsets and they are accessed in the FUN as
sub1.

x - rnorm(100)
grp - gl(4,25)
y - rpois(100, lambda=4)
mydf - data.frame(x,y,grp)
with(mydf, plot(x,y))
by (mydf, list(grp), function(sub1) lines(lowess(sub1$x, sub1$y)))

Hope that helps

On 1/4/06, Dean Sonneborn [EMAIL PROTECTED] wrote:
 I'm using this code to plot a smoothed line.  These two columns of data
 really represent 4 groups and I'd like to plot a separate line for each
 group but have them all in the same plot. The R-Docs for lowess do not
 seem to indicate some type of GROUPS=var_name option. What would be
 the syntax for this?

 plot(AWGT ~ lipid )
 lines(lowess(lipid , AWGT, f=.8))


 --
 Dean Sonneborn, MS
 Programmer Analyst
 Department of Public Health Sciences
 University of California, Davis
 (530) 754-9516

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



--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

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


Re: [R] multiple lowess line in one plot

2006-01-04 Thread Deepayan Sarkar
On 1/4/06, Gregory Snow [EMAIL PROTECTED] wrote:
 Here is one approach using lattice (trellis) graphics:

 tmp.state - data.frame( Frost=state.x77[,'Frost'],
   Murder=state.x77[,'Murder'],
   Region=state.region)

 library(lattice)
 trellis.par.set(col.whitebg())
 xyplot( Murder ~ Frost, groups=Region, data=tmp.state,
   panel.groups=function(...){panel.loess(...);panel.xyplot(...)}
 ,span=.8)

which can be shortened to

xyplot(Murder ~ Frost, groups=Region, data=tmp.state,
   type = c('p', 'smooth'), span = .8)

-Deepayan

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


Re: [R] multiple lowess line in one plot

2006-01-04 Thread hadley wickham
 xyplot( Murder ~ Frost, groups=Region, data=tmp.state,
 panel.groups=function(...){panel.loess(...);panel.xyplot(...)}
 ,span=.8)

or more simply (but with less control over options)

xyplot( Murder ~ Frost, groups=Region, data=tmp.state, type=c(p,smooth))

Hadley

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