如何修改此代码,以便在x轴上看到每个月的“1月10日,2月10日... 1月11日,3月11日... 1月13日... 12月13日”?
现在我只看到一年中的第一个月 .
以下是您可以运行的代码:
library("zoo")
Factors <- matrix(seq(from=1, to=9, by=1), nrow=3,ncol=3)
Factors
datesNumeric <- cbind(20110101, 20120220,20130801)
dates <- as.Date(as.character(datesNumeric), format="%Y%m%d")
ticks <- seq(dates[1], dates[length(dates)], by = "1 month") #I make some ticks
ticks
my.panel <- function(x, y, ..., pf = parent.frame()) {
grid(NA,NULL)
#abline(v=seq(1,168,24),col = "lightgray", lty = "dotted", lwd = par("lwd"))
lines(x, y, ...)
#if bottom panel --> I don't think I need this if statement...Do I?
if (with(pf, length(panel.number) == 0 ||panel.number %% nr == 0 || panel.number == nser)) {
#axis(1, at = ticks, labels = ticks)
# axis.Date(1, at = ticks, format= "%m-%y", las = 1)
}
}
plot(zoo(x=Factors,order.by=ticks), main="Factors 1,2, & 3", ylab=c("Factor 1","Factor 2","Factor 3") , xlab= "Date", panel = my.panel,yax.flip=FALSE,col=1:3,format='%b-%y')
有任何想法吗?
1 回答
试试这个: