R 一些衰退没有出现在情节上

R 一些衰退没有出现在情节上,r,plot,time-series,R,Plot,Time Series,我使用弗雷德的年度数据来绘制上一时期GDP的百分比变化。然而,当我尝试使用FRED提供的USRec时,较小的衰退(持续不到一年的衰退)不会出现。我相信这是因为我的数据是每年一次的,衰退是每月一次的,但是有没有办法绕过这个问题呢 rGDP = getSymbols('A191RL1Q225SBEA',src='FRED',auto.assign=FALSE) rate = subset(rGDP, index(rGDP)>="1960-01-01") rate2 <- ts(rate,

我使用弗雷德的年度数据来绘制上一时期GDP的百分比变化。然而,当我尝试使用FRED提供的USRec时,较小的衰退(持续不到一年的衰退)不会出现。我相信这是因为我的数据是每年一次的,衰退是每月一次的,但是有没有办法绕过这个问题呢

rGDP = getSymbols('A191RL1Q225SBEA',src='FRED',auto.assign=FALSE)
rate = subset(rGDP, index(rGDP)>="1960-01-01")
rate2 <- ts(rate, start=c(1960,1), frequency=4)
yearly <- aggregate(rate2, nfrequency=1, mean)
这就给了我:


除了获取更细粒度的数据,您什么也做不了。请看这里:
rec <- getSymbols("USREC",src="FRED",auto.assign=FALSE)
start <- index(rec[which(diff(rec$USREC)==1)])
end   <- index(rec[which(diff(rec$USREC)==-1)-1])
cycles.dates <- paste(format(start,"%Y-%m"),format(end[-1],"%Y-%m"),sep="/")
chart.TimeSeries(rate,
    period.areas=cycles.dates, 
    period.color="lightblue", 
    lwd=1,
    xlab="",
    ylab="",
    main="",
    minor.ticks=FALSE,
    las=1)