I have a \"monthly data\" I want to plot the data such that I get a date in the format %Y-%m\" (2001-01)
on the x-axis. Say my data is pcp <- rnorm(24
I find that the excellent xts
package is the best way to store your data. If you've not got it, you can download with install.packages('xts')
.
Let's start from basics -- including making pcp
, as you've not supplied it.
require(xts)
pcp <- rnorm(24)
PCP <- ts(pcp, frequency = 12, start = 2001)
plot(as.xts(PCP), major.format = "%Y-%m")
This gives you a chart something like the following. You can tweak the dates by altering the string passed to major.format
. For example, "%b-%y"
yields dates in the Jan-01
format for Jan 2001.