简体   繁体   中英

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: 在此处输入图片说明

You can find the text file with the dates here .

Thanks.

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)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM