multiple lowess line in one plot

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

multiple lowess line in one plot

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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: multiple lowess line in one plot

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: [hidden email]
[mailto:[hidden email]]On Behalf Of Dean Sonneborn
Sent: Wednesday, January 04, 2006 8:54 AM
To: [hidden email]
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: multiple lowess line in one plot

MMcIntosh
In reply to this post by Dean Sonneborn
## 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: [hidden email]
[mailto:[hidden email]] On Behalf Of Dean Sonneborn
Sent: Wednesday, January 04, 2006 10:54 AM
To: [hidden email]
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: multiple lowess line in one plot

Gregory Snow
In reply to this post by Dean Sonneborn
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
[hidden email]
(801) 408-8111
 
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Dean Sonneborn
> Sent: Wednesday, January 04, 2006 9:54 AM
> To: [hidden email]
> 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: multiple lowess line in one plot

PaulJohnson32gmail
In reply to this post by Dean Sonneborn
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 <[hidden email]> 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
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: multiple lowess line in one plot

Deepayan Sarkar
In reply to this post by Gregory Snow
On 1/4/06, Gregory Snow <[hidden email]> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: multiple lowess line in one plot

hadley wickham
In reply to this post by Gregory Snow
> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html