Skip to content

Instantly share code, notes, and snippets.

@mattm
mattm / advanced-homepage-scrolling-analytics.js
Created September 5, 2016 18:23
Advanced homepage analytics
// Add this below the analytics tracking:
if ( sectionName === 'pricing' ) {
setCookie( 'viewed_homepage_pricing', 'true' );
}
// Then in your sign up event:
analytics.record( 'Signed Up', {
viewed_pricing: getCookie( 'viewed_homepage_pricing' ) === 'true'
} );
@mattm
mattm / signups-by-week.txt
Created April 19, 2017 12:32
Signups by Week
+------------+----------+---------+
| week | plan | signups |
+------------+----------+---------+
| 2017-01-26 | Bronze | 10 |
| 2017-01-26 | Gold | 55 |
| 2017-01-26 | Standard | 108 |
| 2017-02-05 | Bronze | 6 |
| 2017-02-05 | Iron | 1 |
| 2017-02-05 | Gold | 37 |
| 2017-02-05 | Standard | 142 |
@mattm
mattm / stacked-area-chart-gaps.R
Created April 19, 2017 12:33
Stacked Area Chart - With Gaps
library(ggplot2)
data <- read.csv("dummy-data.csv", sep = "\t")
g <- ggplot(data, aes(x = week, y = signups, group = plan, fill = plan)) +
geom_area()
print(g)
@mattm
mattm / expand-grid-weeks-plans.R
Created April 19, 2017 20:32
Expand Grid Example
week plan
1 2017-01-26 Bronze
2 2017-02-05 Bronze
3 2017-02-12 Bronze
4 2017-02-19 Bronze
5 2017-02-26 Bronze
6 2017-01-26 Gold
7 2017-02-05 Gold
8 2017-02-12 Gold
9 2017-02-19 Gold
@mattm
mattm / full-join-example.txt
Created April 19, 2017 20:36
R Full Join Result
week plan signups
1 2017-01-26 Bronze 10
2 2017-01-26 Gold 55
3 2017-01-26 Standard 108
4 2017-02-05 Bronze 6
5 2017-02-05 Iron 1
6 2017-02-05 Gold 37
7 2017-02-05 Standard 142
8 2017-02-12 Bronze 17
9 2017-02-12 Iron 2
@mattm
mattm / stacked-area-chart-data-without-gaps.txt
Created April 19, 2017 20:39
Stacked Area Chart Data Without Gaps
week plan signups
1 2017-01-26 Bronze 10
2 2017-01-26 Gold 55
3 2017-01-26 Iron 0
4 2017-01-26 Platinum 0
5 2017-01-26 Silver 0
6 2017-01-26 Standard 108
7 2017-02-05 Bronze 6
8 2017-02-05 Gold 37
9 2017-02-05 Iron 1
@mattm
mattm / stacke-area-chart-without-gaps-v1.R
Last active April 19, 2017 20:41
Stacked Area Chart without Gaps - v1
data <- read.csv("data.csv", sep = "\t")
weeks <- unique(data$week)
plans <- unique(data$plan)
combinations <- expand.grid(week = weeks, plan = plans)
data <- full_join(data, combinations, by = c("week" = "week", "plan" = "plan")) %>%
mutate(signups = ifelse(is.na(signups), 0, signups)) %>%
arrange(week, plan)
@mattm
mattm / stacked-area-chart-tidyr-solution.R
Created April 19, 2017 20:43
Stacked Area Chart - Tidyr Solution
data <- read.csv("data.csv", sep = "\t")
data <- data %>%
tidyr::spread(key = plan, value = signups, fill = 0) %>%
tidyr::gather(key = plan, value = signups, - week) %>%
arrange(week, plan)
g <- ggplot(data, aes(x = week, y = signups, group = plan, fill = plan)) +
geom_area(position = "stack")
@mattm
mattm / spread-data.txt
Created April 19, 2017 20:47
Tidyr Spread Data
week Bronze Gold Iron Platinum Silver Standard
1 2017-01-26 10 55 0 0 0 108
2 2017-02-05 6 37 1 0 0 142
3 2017-02-12 17 42 2 0 0 119
4 2017-02-19 11 26 0 1 4 70
5 2017-02-26 13 0 0 0 5 52
@mattm
mattm / spread-and-gather.txt
Created April 19, 2017 20:53
Spread and Gather Result
week plan signups
1 2017-01-26 Bronze 10
2 2017-01-26 Gold 55
3 2017-01-26 Iron 0
4 2017-01-26 Platinum 0
5 2017-01-26 Silver 0
6 2017-01-26 Standard 108
7 2017-02-05 Bronze 6
8 2017-02-05 Gold 37
9 2017-02-05 Iron 1