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/0e2e9fb44290260422e7 to your computer and use it in GitHub Desktop.
Save AmritPatel/0e2e9fb44290260422e7 to your computer and use it in GitHub Desktop.
Looks at "mt vernon va" search frequency over time to determine most popular weeks for visiting Washington's Mt. Vernon estate
# Looks at "mt vernon va" search frequency over time to determine most popular
# weeks 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/a5d2e5e1dad641c45d56/raw/998677343266c2471b33027ae43b576abfdb07fb/mt_vernon_weekly.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, Date, day, 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)
)
# Filter the data to obtain only top scoring weeks
topscore <- filter(arrange(case, year, month, day), mt.vernon.va > 0.5, year > "11")
# Plot the top weeks over specified two year period
r1 <- nPlot(mt.vernon.va ~ Date,
group = "year",
data = topscore,
type = 'multiBarChart',
size = list(const = 3)
)
# Chart available @ http://rcharts.io/viewer/?aa1a021dbc4b7c6b5848
#r1$publish("\"mt vernon va\" search frequency over time to determine most popular weeks 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