做时间序列的时候,诸位useR有没有为如何定义坐标轴上的数字(比如说,数据对应的年份)而烦恼过?毕竟R没有matlab,S+那样友好的“鼠标点点”界面。
“axes"
的命令设置就是为了解决这一问题。当然,如果你的时间数据是characteristic的也好办(直接画就可以了)
给个例子比较好说。先simulate一堆数据。然后关键在于画坐标轴。
set.seed(1234)
alpha0<-0
alpha1<-0.99
W<-0.15^2
hsim0<-0
n<-1000
hsim<-rep(0,n)
error<-rnorm(n,0,sqrt(W))
hsim[1]<-alpha0+alpha1*hsim0+error[1]
for (t in 2:n){
hsim[t]<-alpha0+alpha1*hsim[t-1]+error[t]
}
sigma<-exp(hsim/2)
Y<-rnorm(n,0,sigma)
#postscript("Ysim.eps",horizontal=T,onefile=F,pointsize=12)
plot(Y,type="l",col=4,axes=F) # Do not let R plot axises
axis(1,at=seq(0,1000,by=1000/4),c("01/1997",1998,1999,2000,"01/2001")) # Plot your own "X" axis
axis(2) # Plot your own "Y" axis
#dev.off()
搞定。美观大方,简单易用。
PS: 关于画图的例子,在我贴的 Econometrics in R 里面有不少。祝大家好运!
[此贴子已经被anning189于2007-4-18 17:14:44编辑过]