lourencoj
lourencoj

Reputation: 362

R plotting, date on x axis

I know there are quite a few posts on plotting date values in axis. However, none seem to help. I basically want to have dates in the x-axis with the format "%d-%m-%Y". From the posts, this should be simply:

dat=read.table("TS.table",header=TRUE)
d=as.Date(dat$Date,format="%Y-%m-%d")
plot(d,1:length(d), xaxt="n", xlab="", ylab="")
axis.Date(1, at = seq(d[1], d[length(d)], by="month"),
    labels= seq(d[1], d[length(d)], by="month"),
    format="%d-%m-%Y", las = 2)

However, i get: enter image description here

You can find the text file with the dates here.

Thanks.

Upvotes: 2

Views: 5393

Answers (1)

Sven Hohenstein
Sven Hohenstein

Reputation: 81733

Don't use the labels argument when you use format:

axis.Date(1, at = seq(d[1], d[length(d)], by = "month"),
          format = "%d-%m-%Y", las = 2)

enter image description here

Upvotes: 1

Related Questions