Skip to content

Instantly share code, notes, and snippets.

@jonchang
Created September 10, 2019 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonchang/e5a9c8871fcaef2d83a88df59ad56065 to your computer and use it in GitHub Desktop.
Save jonchang/e5a9c8871fcaef2d83a88df59ad56065 to your computer and use it in GitHub Desktop.
#!/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