-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.R
More file actions
64 lines (45 loc) · 1.81 KB
/
main.R
File metadata and controls
64 lines (45 loc) · 1.81 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
library(tidyverse)
views_quantiles <- paper_stats %>%
filter(is.na(pub_date) | pub_date > traffic_date) %>%
select(collection, views_per_day, downloads_per_day) %>%
nest(-collection) %>%
mutate(views_q = map(data, ~ quantile(.$views_per_day, probs = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95))),
# downloads_q = map(data, ~ quantile(.$downloads_per_day, probs = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95)))
views_q = map(views_q, ~ bind_rows(.) %>% gather())) %>%
select(-data) %>%
unnest()
ggplot(views_quantiles,
aes(x = 1, y = value, color = key)) +
geom_point() +
facet_wrap(~collection) +
theme_bw()
# summarize_at(vars(views_per_day, downloads_per_day),
# quantile, probs = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95))
# # summarize(views_q = quantile(views, probs = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95)),
# downloads_q = quantile(views, probs = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95)))
selected_ids <- sample(to_plot$id, 100)
temp <- db %>%
filter(id %in% selected_ids) %>%
mutate(id = factor(id)) %>%
group_by(id) %>%
mutate(views_scaled = views / max(views))
ggplot(temp,
aes(x = traffic_date - posted, y = views, color = id)) +
geom_line() +
theme_bw() +
guides(color = "none")
ggplot(dat %>% filter(collection == "bioengineering"),
aes(x = posted, y = views_per_day)) +
geom_point() +
geom_quantile() +
coord_cartesian(ylim = c(0, 200)) +
theme_bw()
views_month_1 <- db %>%
group_by(collection) %>%
filter(month == posted_month,
year == posted_year)
ggplot(to_plot,
aes(x = views_per_day, y = downloads_per_day)) +
geom_point() +
facet_wrap(~ collection, scales = "free") +
theme_bw(base_size = 20)