##### Script for Slidedeck b1 ### ### ### Preamble # load additional functions #source("http://rfs.kvasaheim.com/stat200.R") # load the data dt = read.csv("http://rfs.kvasaheim.com/data/crime.csv") attach(dt) # set the colors ito=numeric() ito["Midwest"] = "#1b9e77" ito["Northeast"] = "#d95f02" ito["South"] = "#7570b3" ito["West"] = "#e7298a" ##### ..... ##### ..... ##### ..... ##### ..... ##### ..... ##### ..... ##### ##### Graphics ### Pie Chart par(las=1, cex.axis=0.8) par(cex.axis=5, font.axis=3 ) pie( table(census4) ) ### Bar Charts # Univariate par(las=1, cex.axis=0.8) barplot( table(census4) ) # Side-By-Side par(las=1, cex.axis=0.8) barplot( table(census4,domPolCulture), beside=TRUE ) par(las=1, cex.axis=0.8) barplot( table(domPolCulture,census4), beside=TRUE ) # Stacked par(las=1, cex.axis=0.8) barplot( table(census4, domPolCulture) ) par(las=1, cex.axis=0.8) barplot( table(domPolCulture, census4) ) # Spiffied Up par(mar=c(4,8,1,3)) par(las=1, cex.axis=0.8) spineplot(table(census4, domPolCulture), xlab="", ylab="" ) par(las=1, cex.axis=0.8) barplot( table(domPolCulture,census4), beside=TRUE ) ### Mosaic Plots mosaicplot( table(census4,domPolCulture) ) mosaicplot( table(domPolCulture, census4) ) ##### Presentation-style Graphics # Nice-looking par( mar=c(4,3,1,1) ) par( family="serif", font.lab=2, font.axis=3 ) par( cex.lab=1.2, cex.axis=0.8 ) par( xaxs="i", yaxs="i" ) par( las=1 ) plot.new() plot.window(xlim=c(0,10), ylim=c(0,100) ) barplot( table(census4), col=c("red4", 3, "#291999", rgb(0.5,0.5,0.5)) ) title( xlab="Census Region", line=2.75) title( ylab="Count of States in Region", line=2.75) abline(h=0, lwd=2) # Original barplot( table(census4) ) ### Alternative par(xaxs="i", yaxs="i") par(family="serif",las=1) par(mar=c(4.5,4,1,0.5)) par(font.lab=2, cex.lab=1.2, cex.axis=0.9) plot.new() plot.window( xlim=c(0,5), ylim=c(0,18) ) abline(h=seq(0,20,5), col="grey") axis(2, at=0:4*5) barplot( table(census4), col=c("red4", 3, "#291999", rgb(0.5,0.5,0.5)), add=TRUE) title(xlab="Census Region", line=2.75) title(ylab="Count of States in Region", line=2.75) abline(h=0, lwd=2) ### End of File