[R] Overlaying a moving average curve on top of a barplot

Morten Sickel Morten.Sickel at nrpa.no
Mon Feb 3 12:45:03 CET 2003


Jose Santos Alegria wrote:

>I'm using standard barplot (Windows version 1.6.2 of R) to represent a
certain weekly 
>metric "v" and I would like to properly overlay on top of it its moving
average "mean.8" 
>(window of 8 weeks). I must be doing something wrong since the moving
average (using >"lines") doesn't overlay properly, i.e., both x-scales do
not match!

Have you considered using "filter"? I made a somehov similiar plot this way:
(prec being a data frame with 'columns' date with dates of measurements and
prec, precipitation at the actual date)

<code>
  plot(prec)
  lines(prec$date,filter(prec$value,c(0.25,0.25,0.25,0.25))) 
</code>

Points showing actual measurements and a four periods moving average  as a
line.


Hope this helps.

Morten

-- 
Morten Sickel
Norwegian Radiation Protection Authority
http://www.nrpa.no




More information about the R-help mailing list