2015-08-20 88 views
0

當我讓plot繪製軸時,gridticksby default對齊。將網格與刻度對齊

然而,我的劇情有所涉及:

mytime <- as.POSIXct("2015-08-20") + seq(0,by=3600,length.out=7*24) 
plot(x=mytime,y=rnorm(7*24),xaxt="n") 
ticks <- mytime[seq(1,by=12,to=length(mytime))] 
axis(1, ticks, strftime(ticks, "%a %H:%M")) 
grid(ny=NULL,nx=14) 

,我不能讓gridticks對齊:

grid and ticks do not align

如何使他們靠攏?

回答

0

貌似是答案:

mytime <- as.POSIXct("2015-08-20") + seq(0,by=3600,length.out=7*24) 
plot(x=mytime,y=rnorm(7*24),xaxt="n") 
ticks <- c(mytime[seq(1,by=12,to=length(mytime))],mytime[1]+7*24*3600) 
axis(1, ticks, strftime(ticks, "%a %H:%M")) 
grid(ny=NULL,nx=NA) 
abline(v=ticks[seq(1,length(ticks),2)],lty="dotted",col="lightgray") 

enter image description here