Re: [R] Lattice plot with fitted curves

From: David Scott <>
Date: Fri 01 Sep 2006 - 22:38:49 GMT

On Fri, 1 Sep 2006, hadley wickham wrote:

>> I have some data which consists of time series for a number of sites. It
>> appears that there is not much autocorrelation in the data and I have
>> fitted a cubic for each site using lm. I would like to obtain a lattice
>> plot with one panel for each site and showing the original data, and the
>> fitted cubic.

I haven't looked at ggplot yet so it might take a while to explore this solution, especially since Deepayan's worked for me.

Seems like ggplot is interesting though.



> This is very easy to do with ggplot:
> install.packages("ggplot")
> library(ggplot)
> p <- ggplot(temp, . ~ LocCode, aes=list(y=Density, x=Year))
> (p <- ggpoint(p))
> ggsmooth(p, method=lm, formula=y~poly(x,3))
> You can also do it with fitted values in another column.
> temp$fitted <- fitted(paraslm1)
> p <- ggplot(temp, . ~ LocCode, aes=list(y=Density, x=Year))
> (p <- ggpoint(p))
> ggline(p, aes=list(y=fitted))
> Hadley

David Scott	Visiting (July 06 to January 07)
 		Department of Probability and Statistics
 		The University of Sheffield
 		The Hicks Building
 		Hounsfield Road
 		Sheffield S3 7RH
 		United Kingdom
Phone:	+44 114 222 3908

______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat Sep 02 08:42:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 07 Sep 2006 - 07:51:17 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.