# Election Example # Source code file election.R pdf("election.pdf") election <- read.table("election.txt", header=T) print(election) # Create barplot for gender. gender.count = table(election$gender) barplot(gender.count, names.arg=c("Female", "Male"), main="Gender Breakdown in Election Results", xlab="Gender", ylab="Count", col=c("green", "yellow")) # Create barplot for candidate preference cand.count = table(election$cand) barplot(cand.count, names.arg=c("Candidate A", "Candidate B"), main="Candidate Preference Breakdown in Election Results", xlab="Candidate Preference", ylab="Count", col=c("red", "blue")) # Create bar stacked barplot for gender and # candidate preference. all.counts = table(election) barplot(all.counts, names.arg=c("Candidate A", "Candidate B"), main="Stacked Barplot of Election Results", xlab="Candidate Preference", ylab="Count", col=rainbow(4)) # Create bar side-by-side barplot for gender and # candidate preference. all.counts = table(election) barplot(all.counts, names.arg=c("Candidate A", "Candidate B"), main="Side-by-side Barplot of Election Results", xlab="Candidate Preference", ylab="Count", col=rainbow(4), beside=TRUE) dev.off( )