0
如何修改此代碼,以便每月查看「Jan-10,Feb-10 ... Jan-11,Mar-11 ... Jan -13..Dec-13「在X軸上?R在多個動物園圖的x軸上顯示月份
現在我只看到一年的第一個月。
這裏是你可以運行代碼:
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')
任何想法?
@GGrothendieck感謝,但你的圖表顯示一月,三月,五月,......我期待每個月去顯示在x軸上:一月-11,Feb-11,Mar-11,Apr-11,... Dec-11,Jan-12,Feb-12 ... Dec-12,Jan-13 ...等等 – user3022875
@ user3022875,那只是因爲它不適合他們。如果你製作的標籤更小,你將得到它們全部。嘗試在'axis'語句中添加'cex.axis = 0.7'。 –