当您想使用网格而不是刻度来更好地显示数据时,这可能是那些(罕见的)情况之一。正如@dirk-eddelbuettel 指出的那样——调整好的轴标签很难,尤其是在这样的密度下。您可能还希望您的标签在绘图内,因此网格会稍微隐藏它们的密度。最容易获得的网格是 with abline
,除非你想玩 ggplot2,但它比 R 中的标准图更丑(个人意见)。另外 - 使情节更广泛。实际上,最好也摆脱围绕情节的框;)以下是 Dirk 方法的模型:
png("strangeplot.png",width=800)
#extend y-axis to fit inside labels and remove box
plot(b,type="n",xaxt="n",yaxt="n",ylab="",xlab="",ylim=c(min(b)-30,max(b)),bty="n"))
#use 'mpg' to get labels inside
axis(1,time(b)[ind], format(time(b)[ind]), las=2, cex.axis=0.6,tick=F,mgp=c(0,-2.5,0))
axis(2,tick=F,las=1)
#you locate lines slightly to the left of label...
abline(h=seq(0,200,by=50),v=time(b)[ind]-0.5,col=gray(0.9))
#...so you need to add extra single line in the end
abline(v=max(time(b)[ind])+0.5,col=gray(0.9))
#plot at the end to get it above grid
points(b,type="l")
dev.off()
