# Re: [R] multiple lowess line in one plot

From: Paul Johnson <pauljohn32_at_gmail.com>
Date: Thu 05 Jan 2006 - 07:15:10 EST

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 <dsonneborn@ucdavis.edu> 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
>

```--
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