Created
November 4, 2015 21:03
-
-
Save jwinternheimer/2b0b154e8848ef61dd41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table); library(dplyr); library(tidyr); library(ggplot2); library(xts) | |
## Import and Tidy | |
stripe <- read.table('~/Downloads/stripe.csv',sep=',',header=T) | |
stripe$start_date <- as.Date(as.POSIXlt(stripe$start, format="%Y-%m-%d %H:%M:%S")) | |
stripe$end_date <- as.Date(as.POSIXlt(stripe$ended_at, format="%Y-%m-%d %H:%M:%S")) | |
## Aggregate Awesome Start Dates and Count Users | |
awesome_start_date <- stripe %>% | |
filter(plan_id == 'pro-annual' | plan_id == 'pro-monthly' | plan_id == 'awesome') %>% | |
group_by(start_date) %>% | |
summarise(users = n_distinct(id)) %>% | |
mutate(cumulative = cumsum(users)) | |
## Plot Daily Awesome Plan Starts | |
ggplot(filter(awesome_start_date,start_date > '2015-01-01'),aes(x=start_date,y=users)) + | |
geom_point(size=1) + | |
geom_line() + | |
geom_smooth() + | |
theme_minimal() | |
## Aggregate Daily Data to Weekly | |
aggregated_awesome <- as.xts(awesome_start_date$users,order.by=as.Date(awesome_start_date$start_date)) | |
awesome_weekly <- apply.weekly(aggregated_awesome,sum) | |
awesome_df <- data.frame(date=index(awesome_weekly), coredata(awesome_weekly)) | |
names(awesome_df) <- c('week','users') | |
## Plot Weekly Awesome Upgrades | |
ggplot(filter(awesome_df,week > '2015-01-01' & week < '2015-11-03'),aes(x=week,y=users)) + | |
geom_point(size=3) + | |
geom_line(size=1) + | |
labs(x='Week',y='',title='Weekly Awesome Upgrades') + | |
theme_minimal() | |
## Check Individual IDs of Awesome Upgrades in a Given Week | |
awesome_week_users <- stripe %>% | |
filter((plan_id == 'pro-annual' | plan_id == 'pro-monthly') & (start_date >= '2015-10-01' & start_date <= '2015-10-07')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment