Skip to content
Prev 367411 / 398502 Next

plotting dates in x axis

Hi Maria,
First, Excel files don't make it through the Mexican Wall. A CSV with
the extension changed to .txt might. You can get all of the years like
this:

aa<-data.frame(var1=runif(180),
 SDATE=paste(sample(1998:2012,180,TRUE),
 sample(1:12,180,TRUE),sample(1:28,180,TRUE),sep="-"))
aa$sdate<-as.Date(aa$SDATE)
plot(aa$sdate,aa$var1,xaxt="n")
library(plotrix)
# set the tick marks at the middle of each year
axis.dates<-as.Date(paste(1998:2012,6,30,sep="-"))
staxlab(1,axis.dates,1998:2012,nlines=3)

Obviously you don't want all of the months, so just add the months to the years:

plot(aa$sdate,aa$var1,xaxt="n")
staxlab(1,axis.dates,format(axis.dates,"%b/%Y"),nlines=3)

Jim


On Tue, Feb 28, 2017 at 2:26 AM, Maria Lathouri via R-help
<r-help at r-project.org> wrote: