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

José Santos Alegria Jose.Alegria at oni.pt
Mon Feb 3 13:43:03 CET 2003

My problem is not with "plot()" but with "barplot()"! I guess it may have to do with the fact that the barplot's bars have a non-negligible width and the moving average line not! Is it?

José A. S. Alegria

-----Original Message-----
From: Morten Sickel [mailto:Morten.Sickel at nrpa.no] 
Sent: segunda-feira, 3 de Fevereiro de 2003 11:43 AM
To: José Santos Alegria; R help (E-post)
Subject: RE: [R] Overlaying a moving average curve on top of a barplot

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)


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

Hope this helps.


Morten Sickel
Norwegian Radiation Protection Authority

More information about the R-help mailing list