-
Notifications
You must be signed in to change notification settings - Fork 145
/
r-downloads.Rmd
168 lines (136 loc) · 3.87 KB
/
r-downloads.Rmd
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---
title: "R Downloads"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
library(scales)
library(countrycode)
theme_set(theme_light())
r_downloads_year_raw <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018-10-30/r_downloads_year.csv")
r_downloads_year <- r_downloads_year_raw %>%
select(-X1) %>%
mutate(country_name = countrycode(country, "iso2c", "country.name"))
```
```{r}
r_downloads_year %>%
count(date) %>%
ggplot(aes(date, n)) +
geom_line() +
expand_limits(y = 0) +
labs(y = "# of R downloads per day")
library(lubridate)
r_downloads_year %>%
count(date) %>%
group_by(weekday = wday(date, label = TRUE)) %>%
summarize(average = mean(n)) %>%
ggplot(aes(weekday, average)) +
geom_line(group = 1) +
expand_limits(y = 0) +
labs(y = "Average downloads per weekday")
```
R is downloaded about 1500 times each weekend day and around 3000 times on a typical weekday (averaged over the last year).
```{r}
r_downloads_year %>%
group_by(week = floor_date(date, "week")) %>%
summarize(n = n_distinct(ip_id)) %>%
filter(week > min(week)) %>%
ggplot(aes(week, n)) +
geom_line() +
expand_limits(y = 0) +
labs(y = "# of R downloads per week (distinct IPs)")
```
What time of day were people installing R?
```{r}
r_downloads_year %>%
mutate(country = countrycode(country, "iso2c", "country.name")) %>%
filter(!is.na(country)) %>%
count(hour = hour(time),
country = fct_lump(country, 8)) %>%
ggplot(aes(hour, n)) +
geom_line() +
expand_limits(y = 0) +
facet_wrap(~ country, scales = "free_y")
```
```{r}
library(countrycode)
r_downloads_year %>%
count(country = countrycode(country, "iso2c", "country.name"), sort = TRUE) %>%
mutate(percent = n / sum(n)) %>%
filter(!is.na(country)) %>%
head(16) %>%
mutate(country = fct_reorder(country, percent)) %>%
ggplot(aes(country, percent)) +
geom_col() +
coord_flip() +
scale_y_continuous(labels = percent_format()) +
labs(title = "What countries install the most R?")
```
More than a third of R installations come from the US.
```{r}
r_downloads_year %>%
mutate(version = fct_lump(version, 8)) %>%
count(date, version) %>%
ggplot(aes(date, n, color = version)) +
geom_line()
```
What operating system do R users use?
```{r}
r_downloads_year %>%
count(country = fct_lump(country, 8),
week = floor_date(date, "week")) %>%
filter(week > min(week)) %>%
ggplot(aes(week, n, color = country)) +
geom_line()
```
### R package downloads
```{r}
package_downloads <- read_csv("http://cran-logs.rstudio.com/2018/2018-10-27.csv.gz")
```
```{r}
package_downloads %>%
filter(country %in% c("US", "IN")) %>%
group_by(country, package, sort = TRUE) %>%
summarize(n = n_distinct(ip_id)) %>%
spread(country, n, fill = 0) %>%
ungroup() %>%
mutate(total = US + IN,
IN = (IN + 1) / sum(IN + 1),
US = (US + 1) / sum(US + 1),
ratio = US / IN) %>%
filter(total >= 1000) %>%
arrange((ratio)) %>%
View()
```
```{r}
library(cranlogs)
cranlogs::cran_downloads(packages = c("tidyverse", "broom"), when = "last-week")
```
### Appendix: Why count only distinct IPs?
```{r}
r_download_gaps <- r_downloads_year %>%
mutate(datetime = as.POSIXlt(date) + time) %>%
arrange(datetime) %>%
group_by(ip_id) %>%
mutate(gap = as.numeric(datetime - lag(datetime))) %>%
filter(!is.na(gap))
```
```{r}
ip_counts <- r_downloads_year %>%
count(ip_id, sort = TRUE)
```
A majority (`r percent(mean(ip_counts$n >= 100))`) of IP addresses that installed R did so more than 100 times in a year.
```{r}
r_download_gaps %>%
ggplot(aes(gap)) +
geom_histogram() +
geom_vline(color = "red", lty = 2, xintercept = 86400) +
scale_x_log10(breaks = 60 ^ (0:4),
labels = c("Second", "Minute", "Hour", "2.5 Days", "120 Days"))
```
```{r}
r_download_gaps
```