#Let's begin by opening the appropiate window for graphics motif() #Now bring the file and store it into a variable called 'x' x_read.table("final",header=T) #Let's store every column separately tim_x$TIM nim_x$NIM pim_x$PIM nwbr_x$NWBR inc_x$INC sr90_x$SR90 cs137_x$CS137 nb_x$NB #4 graphics per page par(mfrow=c(2,2)) #1st histogram hist(sr90,xlab="Strontium-90 content of milk", ylab="Percentage",main="SR90") #2nd histogram #Let's create another variable called logarithm of sr90 lsr90_log(sr90) hist(lsr90,xlab="Logarithm of Strontium-90 content of milk", ylab="Percentage",main="logSR90") #3rd graphic plot(inc,tim,ylab="Total Infant Mortality", xlab="Per Capita Income",main="TIM vs INC",pch="o") #4th graphic #Let's create another variable called logarithm of nwbr lnwbr_log(nwbr) plot(lnwbr,tim,xlab="Logarithm of the Percent of non-white births", ylab="Total Infant Mortality",main="TIM vs log(NWBR)",pch="o") #Now we can print these graphs and continue with another four #5th graphic plot(lsr90,tim,xlab="Logarithm of the Strontium-90 content of milk", ylab="Total Infant Mortality",main="TIM vs log(SR90)",pch="o") #6th graphic: The first variable contains the Infant Mortality of #1961-1970. The second variable contains the log of the SR90 #from 1960-1969 tima_tim[c(49:528)] lsr90a_lsr90[c(1:480)] plot(lsr90a,tima, xlab="Logarithm of the Strontium-90 content of milk", ylab="Total Infant Mortality of the following year", main="Lagged SR90",pch="o") #7th graphic, same idea inc63_inc[c(145:192)] inc60_inc[c(1:48)] inca_(inc63-inc60) plot(inc60,inca,pty="s",ylim=range(inc60)-mean(range(inc60)), xlab="Per Capita Income 1960",ylab="Per Capita Income 1963-1960", main="Income 63 -Income 60 vs Income 60",pch="o") #8th graphic, same idea tim63_tim[c(145:192)] tim60_tim[c(1:48)] tima_(tim63-tim60) sr903_sr90[c(145:192)] sr900_sr90[c(1:48)] sr90a_(sr903-sr900) plot(sr90a,tima,pty="s",ylim=range(sr90a)-mean(range(sr90a)), ylab="Total Infant Mortality 63 - 60", xlab="Strontium-90 content of milk 63 - 60", main="TIM 63-60 vs SR90 63 - 60",pch="o") #9th and 10th graphic better in one page each par(mfrow=c(2,1)) #9th graphic, time series in one plot times_c(1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970) plot(times,c(tim[1],tim[49],tim[97],tim[145],tim[193],tim[241], tim[289],tim[337],tim[385],tim[433],tim[481]),type="l", ylim=c(15,45),xlab="year", ylab="Total Infant Mortality for each state", main="TIM vs year for all states") #this command draws a line for between each value of time for every #state #See that we can do this because the values are ordered so that #by adding 48 to any value we get the same value for the following #year for the same state. By taking the first plot outside the for loop #we ensure that we are printing everything in the same graph. for(w in 2:48){lines(times,c(tim[w],tim[w+48],tim[w+96],tim[w+144], tim[w+192],tim[w+240],tim[w+288],tim[w+336],tim[w+384],tim[w+432], tim[w+480]))} #10th graphic, equal plot(times,c(sr90[1],sr90[49],sr90[97],sr90[145],sr90[193],sr90[241], sr90[289],sr90[337],sr90[385],sr90[433],sr90[481]),type="l", ylim=c(0,55),xlab="year",ylab="Strontium-90 content of milk", main="SR90 vs year for all states") for(ww in 2:48){lines(times,c(sr90[ww],sr90[ww+48],sr90[ww+96], sr90[ww+144],sr90[ww+192],sr90[ww+240],sr90[ww+288],sr90[ww+336], sr90[ww+384],sr90[ww+432],sr90[ww+480]))}