Created
September 10, 2019 08:29
-
-
Save jonchang/e5a9c8871fcaef2d83a88df59ad56065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
library(tidyverse) | |
req <- jsonlite::fromJSON("https://formulae.brew.sh/api/analytics/install-on-request/30d.json")$items | |
inst <- jsonlite::fromJSON("https://formulae.brew.sh/api/analytics/install/30d.json")$items | |
req <- req %>% transmute(formula, install_on_request = as.numeric(str_replace_all(count, ",", ""))) | |
inst <- inst %>% transmute(formula, installs = as.numeric(str_replace_all(count, ",", ""))) | |
together <- full_join(req, inst) %>% mutate(ratio = install_on_request / installs) %>% arrange(ratio) %>% as_tibble() | |
modd <- together %>% filter(!str_detect(formula, "/"), !str_detect(formula, "--"), installs > 100) %>% separate(formula, c("base_formula", "version"), sep = "@", remove = FALSE, fill = "right") | |
versioned <- modd %>% group_by(base_formula) %>% filter(n() > 1) %>% pull(base_formula) | |
modd2 <- modd %>% mutate(group = ifelse(base_formula %in% versioned, base_formula, NA)) %>% arrange(rev(group)) | |
ggplot(modd2, aes(x = installs, y = ratio, label = formula)) + geom_label() + geom_label(aes(fill = group), data = filter(modd2, !is.na(group))) + scale_x_log10() + labs(y = "Ratio of requested installs to total installs", x = "Popularity (30d installs, log10 scale)") + theme_bw() + theme(legend.position = "none") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment