download.file("http://www.openintro.org/stat/data/ames.csv", destfile = "ames.csv")
data <- read.csv("/Users/majerus/Downloads/ames.csv") # update to file path on your computer
# This calculation requires the 'plyr' package
if( !is.element("plyr", installed.packages()[,1]) )
install.packages("plyr")
library(plyr)
mean <- ddply(data, .(Yr.Sold), summarize,
mean_price = mean(SalePrice))
plot(mean$Yr.Sold, mean$mean_price, type = "o")
plot(mean$Yr.Sold, mean$mean_price, type = "o",
xlab = "Year", ylab = "Mean Sale Price", main = "Line Graph of Mean Home Sale Price in Ames, IA", pch = 16,
col = "dark blue", lwd = 3, cex = 2)
# This demo requires the 'ggplot' package
if( !is.element("ggplot2", installed.packages()[,1]) )
install.packages("ggplot2")
suppressPackageStartupMessages(library(ggplot2))
ggplot(mean, aes(Yr.Sold, mean_price)) +
geom_line()
if( !is.element("ggthemes", installed.packages()[,1]) )
install.packages("ggthemes")
if( !is.element("scales", installed.packages()[,1]) )
install.packages("scales")
suppressPackageStartupMessages(library(ggthemes))
suppressPackageStartupMessages(library(scales))
ggplot(mean, aes(Yr.Sold, mean_price)) +
geom_line() +
theme_tufte()
ggplot(mean, aes(Yr.Sold, mean_price)) +
geom_line(color="dark blue", size=2) +
scale_y_continuous("Mean Sale Price", labels = dollar) +
scale_x_continuous("Year") +
ggtitle("Mean Home Sale Price in Ames, IA") +
theme_tufte() +
theme(plot.title = element_text(size = 16, face="bold"))
## This demo requires the 'googleVis' package
if( !is.element("googleVis", installed.packages()[,1]) )
install.packages("googleVis")
suppressPackageStartupMessages(library(googleVis))
suppressPackageStartupMessages(library(scales))
# add names to new data frame as factor
mean$pop.html.tooltip=dollar_format()(mean$mean_price)
# create interactive scatter plot using googleVis
line <- gvisScatterChart(mean,
options=list(tooltip="{isHtml:'True'}",
legend="none", lineWidth=5, pointSize=3,
vAxis="{title:'Mean Sale Price'}",
hAxis="{title:'Year'}",
width=750, height=500))
# plot interactive scatter (use 'plot(Hist)' to view in RStudio)
print(line, 'chart')