我有一张金融活动图表和一些运行金额. 事情变得有点忙,我在区分财政(6月30日结束)和日历年时遇到了困难.有没有办法根据日期将背景设置为不同的颜色?
换句话说,我可以将背景设置为浅绿色,2009-06-30 <date <2010-07-01?
应用@G-Grothendieck 和@vincent 的两条建议 -rect
在zoo
包内使用。zoo
非常适合时间序列的任何可视化。
library(zoo)
#random data combined with time series that starts in 2009-01
v <- zooreg(rnorm(37), start = as.yearmon("2009-1"), freq=12)
plot(v, type = "n",xlab="",xaxt="n")
#this will catch some min and max values for y-axis points in rect
u <- par("usr")
#plot green rect - notice that x-coordinates are defined by date points
rect(as.yearmon("2009-6-30"), u[3], as.yearmon("2010-7-1"), u[4],
border = 0, col = "lightgreen")
lines(v)
axis(1, floor(time(v)))
#customized x-axis labels based on dates values
axis(1,at=c(2009.4, 2010.5),padj=-2,lty=0,labels=c("start","end"),cex.axis=0.8)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
813 次 |
最近记录: |