# We are going to try a new way to read in data using a package that will read # in SAS data files with the extension .sas7bdat install.packages("sas7bdat") library(sas7bdat) staff=read.sas7bdat("staff.sas7bdat") head(staff) attach(staff) # vertical barplot # create dataset of Salary by Job_Title of Sales Rep I,II,III,IV srep<- staff[staff$Job_Title=="Sales Rep. I" | staff$Job_Title=="Sales Rep. II" | staff$Job_Title=="Sales Rep. III" | staff$Job_Title=="Sales Rep. IV",] # for barplot, turn srep into a table with droplevels( ) # droplevels( ) gets rid of the other (unused) job titles that R keeps tsrep=table(droplevels(srep)$Job_Title) barplot(tsrep,horiz=F,main='Sales Representatives') barplot(tsrep,horiz=F,main='Sales Representatives',col=c(1:4),ylim=c(0,70)) barplot(tsrep,horiz=F,main='Sales Representatives',col=rainbow(4),ylim=c(0,65)) barplot(tsrep,horiz=T,main='Sales Representatives') barplot(tsrep,horiz=T,main='Sales Representatives',col=c(1:4),ylim=c(0,70)) barplot(tsrep,horiz=T,main='Sales Representatives',col=rainbow(4),ylim=c(0,65)) # the dredded pie chart :-) # 2D pie(tsrep,names(tsrep)) pie(tsrep,names(tsrep)col=c(1:4)) pie(tsrep,names(tsrep),col=rainbow(levels(tsrep)),main="2D Pie Chart of Sales Representatives") # with percents lbls=names(tsrep) pct=round(tsrep/sum(tsrep)*100) lbls=paste(lbls, pct) # add percents to labels lbls=paste(lbls,"%",sep="") # ad % to labels pie(tsrep,lbls,col=rainbow(length(tsrep)),main="2D Pie Chart of Sales Representatives") # 3D "exploding" pie chart # I couldn't get our data to behave for this one so here is a simple example # from the website called "Quick R" library(plotrix) slices <- c(10, 12, 4, 16, 8) lbls <- c("US","UK","Australia","Germany","France") pie3D(slices,labels=lbls,explode=0.1,main="Pie Chart of Countries") pie3D(slices,labels=lbls,explode=0.5,main="Pie Chart of Countries") pie3D(slices,labels=lbls,explode=1,main="Pie Chart of Countries")