-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.R
45 lines (34 loc) · 1.7 KB
/
main.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
library(tidyverse)
library(plotly)
source("colors.R")
df <- read_csv('libs.csv') %>%
filter(date > '2017-05-22')
first_date = first(df$date)
last_date = last(df$date)
deltas <- df %>%
group_by(library, client) %>%
summarize(first_value=min(frequency),
last_value=max(frequency),
total_frequency=sum(frequency)) %>%
mutate(delta = last_value-first_value,
delta_percent = 100 * (last_value - first_value) / first_value)
top_n = deltas %>% arrange(desc(total_frequency)) %>% head(n=20)
# We care about libraries with highly variable popularity, which exceed a minimum popularity bar.
# Or just libraries which are generally of interest.
interesting_sites <- inner_join(df, deltas) %>%
filter((abs(delta_percent) > 40 & total_frequency > 3500) |
library %in% c("Polymer", "Google Maps", "React", "jQuery"))
#order <- interesting_sites %>% filter(client == "desktop") %>% group_by(library) %>% summarize(v=last(frequency)) %>% arrange(desc(v))
order <- interesting_sites %>% group_by(library) %>% summarize(v=last(frequency)) %>% arrange(desc(v))
interesting_sites$library <- factor(interesting_sites$library, order$library)
interesting_sites %<>%
mutate(text = sprintf("Date: %s<br>Library: %s<br>Page Count: %f", format(date, "%Y/%m/%d"), library, frequency))
plot <- ggplot(interesting_sites, aes(x=date, y = frequency, color=library, text=text, group=1)) +
#plot <- ggplot(interesting_sites, aes(x=date, y = frequency, color=library)) +
geom_line(size=2) +
scale_color_manual(values=colors) +
scale_y_log10() +
facet_wrap(~client, ncol=1) +
ylab("Page count") +
ggtitle("Library Usage")
#ggsave("libraries_over_time.png", plot=plot, width=8, height=10, dpi=200)