# PieCharts -- Create pie charts of car sales # for autosales.txt dataset. # Read data frame from file. autos <- read.table("autosales.txt", header=T, sep="\t") cars <- autos$cars days <- autos$days # Send graphs to disk file. pdf("pie-charts.pdf") # Create simple pie chart. pie(cars) # Add day of week labels and title. pie(cars, labels=days, col=rainbow(length(cars)), main="Car Sales by Day of Week") # Change colors, label using percentages, and add a legend. colors <- c("white", "gray70", "gray90", "gray50", "black") car_labels <- round((cars / sum(cars)) * 100, 1) car_labels <- paste(days, ": ", car_labels, "%", sep="") pie(cars, main="Car Sales by Day of Week", col=colors, labels=car_labels) # Reset graphics output to default. dev.off( )