RMarkdown
This blogpost was created in RStudio using the rmarkdown package. For practice, I wanted to reproduce the plots created during week two and display them along with respective code.
Unfortunately, I only made it half-way, as only the code shows up, not the graphics. I was was hoping it would turn out something sort of like so: http://rpubs.com/audiblediner/74483. Well, it’s a start.
Figure 1
hotdogs <-read.csv("http://datasets.flowingdata.com/hot-dog-contest-winners.csv", sep=",", header=TRUE)
fill_colors <- c()
for ( i in 1:length(hotdogs$New.record) ) {
if (hotdogs$New.record[i] == 1) {
fill_colors <- c(fill_colors, "#821122")
} else {
fill_colors <- c(fill_colors, "#cccccc")
}
}
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year, col=fill_colors, border=NA, space=0.3, xlab="Year", ylab="Hot dogs and buns (HDB) eaten", main="Nathan's Hot Dog Eating Contest Results, 1980-2010")
Figure 2
hot_dog_places <- read.csv('http://datasets.flowingdata.com/hot-dog-places.csv', sep=",", header=TRUE)
names(hot_dog_places) <- c("2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010")
hot_dog_matrix <- as.matrix(hot_dog_places)
barplot(hot_dog_matrix, border=NA, space=0.25, ylim=c(0, 200), xlab="Year", ylab="Hot dogs and buns (HDB) eaten", main="Hot Dog Eating Contest Results, 2000-2010")
Figure 3
subscribers <-
read.csv("http://datasets.flowingdata.com/flowingdata_subscribers.csv", sep=",", header=TRUE)
plot(subscribers$Subscribers, type="h", ylim=c(0, 30000), xlab="Day", ylab="Subscribers")
points(subscribers$Subscribers, pch=19, col="black")
Figure 4
population <-
read.csv("http://datasets.flowingdata.com/world-population.csv", sep=",", header=TRUE)
plot(population$Year, population$Population, type="l", bty="n", ylim=c(0, 7000000000), xlab="Year", ylab="Population")
Figure 5
postage <- read.csv("http://datasets.flowingdata.com/us-postage.csv", sep=",", header=TRUE)
plot(postage$Year, postage$Price, type="s", main="US Postage Rates for Letters, First Ounce, 1991-2010", xlab="Year", ylab="Postage Rate (Dollars)")
Figure 6
unemployment <- read.csv("http://datasets.flowingdata.com/unemployment-rate-1948-2010.csv", sep=",")
scatter.smooth(x=1:length(unemployment$Value), y=unemployment$Value, ylim=c(0,11), degree=2, col="#CCCCCC", span=0.5)
Data and Exercise Sources: Yau, N. (2011). Visualize this: The FlowingData guide to design, visualization, and statistics. Indianapolis, Ind: Wiley Pub.