[R] How to plot several years data with date information by months?

Marc Girondot marc_grt at yahoo.fr
Sat Apr 6 12:04:30 CEST 2013


Le 06/04/13 10:00, ZhaoXing a écrit :
> Hi, all
>
> I have a medium sized data, 6 years. Each observation is a case with a date variable, such as '2004-08-02'.
> Some of the months didn't occur a case.
> I want to plot the 6 years data by month, and the Y_axis is the freqency of cases for each month, meaning 12*6=72 bars or points in the figure.
> I though of a method, 1st, using the months function, then ploting. But I need to assign zero to the months without case. And a lot of other manipulations.
> Is there any simpler way to complete this? or just a simple function exists?
>
> Thanks in advance
>
> ZhaoXing
> ______________________________________________
>
Do you want something like this ?

x <- seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), by="1 day")
y <- sin(1:length(x))+1

plot(x, y, bty="n", type="l", xaxt="n", las=1)
axis(1, at=seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), 
by="1 month"), label=FALSE)
axis(1, at=seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), 
by="1 year"), lwd.ticks=2, label=c(2000:2006))

Sincerely

Marc

-- 
__________________________________________________________
Marc Girondot, Pr

Laboratoire Ecologie, Systématique et Evolution
Equipe de Conservation des Populations et des Communautés
CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079
Bâtiment 362
91405 Orsay Cedex, France

Tel:  33 1 (0)1.69.15.72.30   Fax: 33 1 (0)1.69.15.73.53
e-mail: marc.girondot at u-psud.fr
Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
Skype: girondot



More information about the R-help mailing list