Modify date format on x axis in R?

date, graphics, plot, r

Solution

You should use `format= "%Y-%m"`, to write something like this :

axis.Date(1, at = seq(alvdate[1250], alvdate[1600], length.out=20),
        format= "%Y-%m", las = 2)

Problem

I want to change the format of my plot in R in month year. So currently it is displaying the day too, I want to have only month year. With my data and the R code: ``` plot(alvdate[1250:1600],c(NA,alvlloss)[1250:1600],type="l",lwd=1,main="",xlab="",ylab="log loss",cex.axis=1.2,cex.lab=1.2,xaxt="n") axis.Date(1, at = seq(alvdate[1250], alvdate[1600], length.out=20), labels = seq(alvdate[1250], alvdate[1600], length.out=20), format= "%m/%y", las = 2) ``` I get the picture I get the format yyyy-mm-dd but I want to have yyyy-mm so e.g. ``` 2008-01 2008-02 ``` and so on. I alredy set the format to "%m/%y" but this does not work?

Original source