########################################################################### ### Graph of CO2 Emissions for China and the U.S. ### Produced by Thomas J. Pfaff for sustainabilitymath.org ### March 2023 ########################################################################### ## URL for the data from sustainabilitymath.org dataURL<-"https://sustainabilitymath.org/excel/CO2-R.csv" ## Read data from online csv file Emis <-read.csv(url(dataURL),header=TRUE) names(Emis) ## Define x and y, mostly to save typing x<-Emis$Years.after.1980 y.us<-Emis$US.per.capita.emission..metirc.ton.per.person. y.ch<-Emis$China.per.capita.emission..metirc.ton.per.person. max.y<-max(y.us,y.ch) max.x<-ceiling(max(x)/10)*10 max(Emis$Year) ######################################## ###### Graphs for Word Document ######## ######################################## ## Define some graphing parameters d<-1.25 #dot size 2.25 for webgraph, 1.25 for document ## Create Plot windows(width=7,height=7) plot(x, y.us, type="p", cex=d, pch=10, xlim=c(0,max.x), ylim=c(0,max.y), xlab="Years after 1980", ylab="Metric Ton Per Capita", col="blue") title(main="Per Capita CO2 Emission in Metric Tons\nfor the U.S. and China") points(x, y.ch, type="p", cex=d, pch=10, xlim=c(0,max.x),col="red") grid (NULL,NULL, lty = 6, col = "gray") legend("center", c( "U.S.", "China"), pch=c(10,10), col=c( "blue","red"),cex=2,bty="n") mtext("Thomas J. Pfaff || sustainabilitymath.org",1,4,adj=1) ######################################## ###### Graphs for Web Document ######## ######################################## ## Define some graphing parameters d<-2.25 #dot size 2.25 for webgraph, 1.25 for document ## Create Plot windows(width=7,height=7) par(bg = "#b3c0d7") #Blue background for webgraph, comment out with # for white background. plot(x, y.us, type="p", cex=d, pch=10, xlim=c(0,max.x), ylim=c(0,max.y), xlab="Years after 1980", ylab="Metric Ton Per Capita", col="blue") title(main="Per Capita CO2 Emission in Metric Tons\nfor the U.S. and China") points(x, y.ch, type="p", cex=d, pch=10, xlim=c(0,max.x),col="red") grid (NULL,NULL, lty = 6, col = "gray") legend("center", c( "U.S.", "China"), pch=c(10,10), col=c( "blue","red"),cex=2,bty="n") mtext("Thomas J. Pfaff || sustainabilitymath.org",1,4,adj=1)