############# R code for Hwk 1, problems 3.56-57 ################ # create file prob3.56.txt containing the data with column names mo m2 m3 1 2.25 2.81 2 2.27 2.84 3 2.28 2.86 4 2.29 2.88 5 2.31 2.9 6 2.32 2.92 7 2.35 2.96 8 2.37 2.99 9 2.40 3.02 10 2.42 3.04 11 2.43 3.05 12 2.42 3.05 13 2.44 3.08 14 2.47 3.1 15 2.49 3.1 16 2.51 3.13 17 2.53 3.17 18 2.53 3.18 19 2.54 3.19 20 2.55 3.2 # reads in data and uses col names instead of default V1, V2, V3 ms<-read.table("prob3.56.txt", header=T) # make data columns accessible by name attach(ms) # can now access each data vector by its name. Here's m2 m2 # divide plotting device into 4 regions, and do a scatter plot m2 vs. m3 par(mfcol=c(2,2)) plot(m2,m3,xlab="M2",ylab="M3") title("Scatter plot of M2 vs. M3") # time series plot shows trends better. First just set the axes, and labels plot(mo,m3,type="n",ylim=c(2.25,3.20),xlab="Month",ylab="Money Supply (trillions of dollars)") # now add m2 with line type 1, m3 with line type 2, and connect pts # with lines lines(m2,lty=1) lines(m3,lty=2) # finally, add a legend and title legend(1,3.2,legend=c("M2","M3"),lty=1:2) title("Time series plot of M2 and M3")