# get data from a .sas7bdat file #library(sas7bdat) budget=read.sas7bdat("budget.sas7bdat") # for ease of use attach(budget) month.abb # gives a vector of months, abbreviated names month.name # gives a vector of months, full names # scatterplot plot(Yr2007,Month) # make it a bit prettier # option xaxt = "n" removes the default x-axis labels # axis(side,at= ,labels= ,...) will allow you to make changes to an axis # side: 1=bottom, 2=left, 3=top, 4=right # at: the points at which rick-marks are to be drawn (for 9 you input 1:9) # labels: this can be a value, character, or expression vector of labels plot(Month,Yr2007,main="Scatterplot of Monthly Budgets of 2007",col="red",pch=17,xaxt = "n",ylab='Budget') axis(1, at=1:12, labels=month.abb) # line plot (time-series) # use type="l" option (it's not a one, it's a lowercase L) plot(Month,Yr2007,type="l",main="Time Series of Monthly Budgets of 2007",col="red",pch=17,xaxt = "n",ylab='Budget') axis(1, at=1:12, labels=month.abb) # line plot with the points plot(Month,Yr2007,type="b",main="Time Series of Monthly Budgets of 2007",col="red",pch=17,xaxt = "n",ylab='Budget') axis(1, at=1:12, labels=month.abb) hand=read.csv("handwashing.csv",header=T) attach(hand) # histograms hist(Bacteria,freq=F,main="Normal Curve Over Histogram of Bacteria") # histograms with density curve xbar=mean(Bacteria) stdev=sd(Bacteria) hist(Bacteria,freq=F,main="Normal Curve Over Histogram of Bacteria") curve(dnorm(x,xbar,stdev),col="darkblue",lwd=2,add=TRUE,yaxt="n") xbar=mean(Bacteria) stdev=sd(Bacteria) hist(Bacteria,freq=F,main="Normal Curve Over Histogram of Bacteria",col=terrain.colors(5)) curve(dnorm(x,xbar,stdev),col="darkblue",lwd=2,add=TRUE,yaxt="n") xbar=mean(Bacteria) stdev=sd(Bacteria) hist(Bacteria,freq=F,main="Normal Curve Over Histogram of Bacteria",col=heat.colors(5)) curve(dnorm(x,xbar,stdev),col="darkblue",lwd=2,add=TRUE,yaxt="n") xbar=mean(Bacteria) stdev=sd(Bacteria) hist(Bacteria,freq=F,main="Normal Curve Over Histogram of Bacteria",col=grey.colors(5)) curve(dnorm(x,xbar,stdev),col="darkblue",lwd=2,add=TRUE,yaxt="n") # grouped histograms install.packages("lattice") library(lattice) histogram(~Bacteria | Method,data=hand,main="Histograms of Bacteria Counts by Method") histogram(~Bacteria | Method,data=hand,main="Histograms of Bacteria Counts by Method",col=grey.colors(5)) # Boxplots # boxplot of just counts boxplot(Bacteria,main='Boxplot of Bacteria Counts') # boxplot of counts by method levels(hand$Method)=c('ABS','AS','S','W') hand.names=c("Anti-Bacterial Soap","Alcohol Spray","Soap",'Water') boxplot(Bacteria~Method,main='Bacteria Counts by Handwashing Method',xaxt="n") axis(1,at=1:4,labels=levels(hand$Method)) legend('topleft',hand.names,cex=0.45) # contour plot # starting simple data(volcano) require(grDevices) # for colours and is part of the base packages -- no installation necessary filled.contour(volcano, color = terrain.colors, asp = 1) # now with more bells and wistles x <- 10*1:nrow(volcano) y <- 10*1:ncol(volcano) filled.contour(x, y, volcano, color = terrain.colors, plot.title = title(main = "The Topography of Maunga Whau", xlab = "Meters North", ylab = "Meters West"), plot.axes = { axis(1, seq(100, 800, by = 100)) axis(2, seq(100, 600, by = 100)) }, key.title = title(main = "Height\n(meters)"), key.axes = axis(4, seq(90, 190, by = 10))) # maybe also asp = 1 mtext(paste("filled.contour(.) from", R.version.string), side = 1, line = 4, adj = 1, cex = .66)