I am trying to show that there is a wierd “bump” in some data I am analysing (it is to do with market share. My code is here:-
qplot(Share, Rate, data = Dataset3, geom=c("point", "smooth"))
(I appreciate that this is not very useful code without the dataset).
Is there anyway that I can get the numeric vector used to generate the smoothed line out of R? I just need that layer to try to fit a model to the smoothed data.
Any help gratefully received.
Yes, there is. ggplot uses the function
loessas the default smoother ingeom_smooth. this means you can useloessdirectly to estimate your smoothing parameters.Here is an example, adapted from
?loess:Use
loessto estimate the smoothed data, andpredictfor the estimated values::The estimates are now in
pc$fitand the standard error inpc$fit.se. The following bit of code extraxts the fitted values into a data.frame and then plots it usingggplot: