# clear workspace and close graphs
rm(list=ls())
graphics.off()
# load quantmod package
require(quantmod)
# input the NBER recession peak and trough dates
peaks <- c(1918+8/12, 1920+1/12, 1923+5/12, 1926+10/12, 1929+8/12,
1937+5/12, 1945+2/12, 1948+11/12, 1953+7/12, 1957+8/12, 1960+4/12,
1969+12/12, 1973+11/12, 1980+1/12, 1981+7/12, 1990+7/12, 2001+3/12,
2007+12/12) - 0.5/12
troughs <- c(1919+3/12, 1921+7/12, 1924+7/12, 1927+11/12, 1933+3/12,
1938+6/12, 1945+10/12, 1949+10/12, 1954+5/12, 1958+4/12, 1961+2/12,
1970+11/12, 1975+3/12, 1980+7/12,1982+11/12,1991+3/12,2001+11/12,
2009+6/12) - 0.5/12
# load the data from FRED
getSymbols(c("INDPRO","TCU"),src="FRED")
# coerce the xts objects into ts objects
ind <- ts(INDPRO,start=c(1919,1),freq=12)
tcu <- ts(TCU,start=c(1967,1),freq=12)
# force the series to have the same starting and ending dates
A <- ts.intersect(ind,tcu)
indpro <- A[,1]
tcu <- A[,2]
# set up the margins for our graph
op<-par(mar=c(5,4,4,6)+.1)
# graph indpro first
plot(indpro,type="l",col="black",xlab=NULL,las=1,
ylab="Industrial Production Index (2007=100)")
# add the graph caption
title(main="Industrial Production (black) and Capacity Utilization: Total Industry (blue), \n Monthly from January 1960 to Today")
# add the recession shading BEFORE new=T command --- use a red shade
rect(xleft=peaks,xright=troughs,ytop=1.1*max(indpro),ybottom=0.8*min(indpro),
col=rgb(1,0,0,alpha=.1),density=100)
# use same plot frame to add tcu
par(new=TRUE)
plot(tcu,type="l",col="blue",xaxt="n",yaxt="n",xlab="",ylab="")
# select the right side of plot
axis(4, las=1)
# and write the y2 label
mtext("Percentage of Capacity",side=4,line =3)
mtext("Recessions are indicated by shaded regions. \n Source: Federal Reserve Bank of St. Louis (FRED)",side=1,line=3.5,cex=0.75)
par(op)