Skip to content

Instantly share code, notes, and snippets.

@AmritPatel
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmritPatel/bf18dae7e18b498f3873 to your computer and use it in GitHub Desktop.
Save AmritPatel/bf18dae7e18b498f3873 to your computer and use it in GitHub Desktop.
Looks at "mt vernon va" search frequency over time to determine most popular months for visiting Washington's Mt. Vernon estate
# Looks at "mt vernon va" search frequency over time to determine most popular
# months for visiting Washington's Mt. Vernon estate
library(rCharts)
library(dplyr)
library(stringr)
library(RCurl)
# Read in the data
x <- getURL("https://gist.githubusercontent.com/AmritPatel/4665ebd02f810fc10b37/raw/b24e1c6210e21c89db2aa4037b540bfebf26cda0/mt_vernon.csv")
mt_vernon <- read.csv(text = x)
# Use dataframe wrapper
mt_vernon_df <- tbl_df(mt_vernon)
# Break up the date filed by month, day, and year for futher processing
break_date <- mutate(mt_vernon_df,
month = str_sub(str_extract(Date, "\\d\\d?/"), end = -2),
day = str_sub(str_extract(Date, "/\\d\\d?/"), start = 2, end = -2),
year = str_sub(str_extract(Date, "/\\d\\d?$"), start = 2)
)
# Only select the columns we need
case <- select(break_date, month, year, mt.vernon.va)
# Plot of data as a function of year (grouped by month)
r1 <- nPlot(mt.vernon.va ~ year,
group = "month",
data = case,
type = 'multiBarChart',
size = list(const = 3)
)
# Average the monthly data over years
month_avg <- summarise(group_by(case, month),
avg_over_years = mean(mt.vernon.va)
)
# Plot the monthly data average over years
r2 <- nPlot(avg_over_years ~ month,
data = month_avg,
type = 'multiBarChart',
size = list(const = 3)
)
# Chart available @ http://rcharts.github.io/viewer/?c24af1f90fd5f6370bfc
#r2$publish("\"mt vernon va\" search frequency over time to determine most popular months for visiting Washington's Mt. Vernon estate", host = 'gist')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment