-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforkingData.qmd
More file actions
99 lines (76 loc) · 2.84 KB
/
forkingData.qmd
File metadata and controls
99 lines (76 loc) · 2.84 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
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
---
title: "Garden of Forking Data"
author: "Jaden Earl"
format: html
---
## Observable JS
This Quarto document is made interactive using Observable JS. Interactive documents allow readers to modify parameters and see the results immediately. Learn more about OJS interactive documents at <https://quarto.org/docs/interactive/ojs/>.
## Bubble Chart
This example uses a D3 bubble chart imported from Observable HQ to analyze commits to GitHub repositories.
Select a repository to analyze the commits of:
```{r install dependencies, eval = FALSE, echo = FALSE}
packages <- c("ape", "bayesplot", "brms", "broom", "dagitty", "devtools", "flextable", "GGally", "ggdag", "ggdark", "ggmcmc", "ggrepel", "ggthemes", "ggtree", "ghibli", "gtools", "invgamma", "loo", "patchwork", "posterior", "psych", "rcartocolor", "Rcpp", "remotes", "rstan", "santoku", "StanHeaders", "statebins", "tidybayes", "tidyverse", "viridis", "viridisLite", "wesanderson")
#install.packages(packages, dependencies = T)
devtools::install_github("stan-dev/cmdstanr")
devtools::install_github("EdwinTh/dutchmasters")
devtools::install_github("gadenbuie/ggpomological")
devtools::install_github("GuangchuangYu/ggtree")
devtools::install_github("rmcelreath/rethinking")
devtools::install_github("UrbanInstitute/urbnmapr")
```
```{r}
library(pdftools)
library(tidyverse)
# Extract text
text <- pdf_text("~/Documents/Intellectual Fun/genericStats/p_hacking.pdf")
# Convert to tibble for manipulation
pdf_data <- tibble(
page = seq_along(text),
content = text
) %>%
# Clean up common issues
mutate(
content = str_replace_all(content, "\\s+", " "),
content = str_trim(content)
)
writeLines(pdf_data$content, "~/Documents/Intellectual Fun/genericStats/p_hacking.txt")
write_file(paste(pdf_data$content, collapse = "\n\n"), "~/Documents/Intellectual Fun/genericStats/p_hacking.txt")
```
```{ojs}
//| echo: false
//| panel: input
viewof repo = Inputs.radio(
[
"pandas-dev/pandas",
"tidyverse/ggplot2",
],
{ label: "Repository:", value: "pandas-dev/pandas"}
)
```
Fetch the commits for the specified `repo` using the GitHub API:
```{ojs}
d3 = require('d3')
contributors = await d3.json(
"https://api.github.com/repos/" + repo + "/stats/contributors"
)
commits = contributors.map(contributor => {
const author = contributor.author;
return {
name: author.login,
title: author.login,
group: author.type,
value: contributor.total
}
})
```
Note that the `repo` variable is bound dynamically from the radio input defined above. If you change the input the contributors query will be automatically re-executed.
View the commits sorted by most to least:
```{ojs}
Inputs.table(commits, { sort: "value", reverse: true })
```
Visualize using a D3 bubble chart imported from Observable HQ:
```{ojs}
import { chart } with { commits as data }
from "@d3/d3-bubble-chart"
chart
```