2

Let's say I have this:

cplot <- ggplot(mtcars, aes(qsec, wt)) + 
  geom_point(alpha=0.2)+
  stat_smooth(geom='point', n=30, color='red') +
  stat_smooth(geom='line', n=30, color='red')
cplot

enter image description here

How can do something similar but computing the mean of the points in each segment instead of fancy regressions?

Note that I don't ask for solutions that involve preprocessing the data. I would like to do this on the fly (if possible).

(the mean of the n-th segment, or with sliding windows, it doesn't really matters since I won't use n=30 but rather 2 or 3 to avoid much distorsions)

Brian
  • 7,900
  • 1
  • 27
  • 41
alberto
  • 2,625
  • 4
  • 29
  • 48
  • Possible duplicate of [Add Moving average plot to time series plot in R](http://stackoverflow.com/questions/13840761/add-moving-average-plot-to-time-series-plot-in-r) – zx8754 Sep 02 '16 at 11:07
  • Yes and no. I know I can preprocess this, but I would like to do this on the fly, e.g. playing with geom_stats. Or to know whether it can be done! – alberto Sep 02 '16 at 11:18
  • That is why it says "Possible duplicate... ". – zx8754 Sep 02 '16 at 11:37
  • How about [this post](http://stackoverflow.com/questions/21489385)? – zx8754 Sep 02 '16 at 11:47

0 Answers0