Message-ID: <4E897B6C.4000504@knmi.nl>
Date: 2011-10-03T09:07:56Z
From: Paul Hiemstra
Subject: ggplot2 - extracting values of smooth
In-Reply-To: <b1a6e25d-e84c-48c5-bbf9-940500390f86@n15g2000vbn.googlegroups.com>
On 09/30/2011 04:39 PM, dM/ wrote:
> Suppose that I'm working on Hadley's diamond dataset and I want to
> review the relationship between price, colour and carat.
>
> I might run the following:
>
> library(ggplot2)
>
> #plot scatter and add some hex binning
> q<-qplot(carat,price,data=diamonds, geom=c("hex"),
> main="Variability of Diamond Prices by Carat and Colour")
>
> #facet to get one scatter for each colour, plus overlay a black
> coloured loess smoothed line showing the trends in the data
>
> q +
> facet_wrap(~color,ncol=2)+geom_smooth(aes(group=1),colour=I("black"))
>
> Nice picture, but how do I extract the values of the smoothed line?
>
> Many thanks, dM/
>
> ______________________________________________
> R-help at 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.
...and if you want to extract the smoothed lines per factor (as when
using facet_wrap) use ddply.
good luck,
Paul
--
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770