Skip to content

Instantly share code, notes, and snippets.

@tylerlittlefield
Created November 27, 2018 04:43
Show Gist options
  • Save tylerlittlefield/32c1a34961367d05b65ca1b30bfdb0fb to your computer and use it in GitHub Desktop.
Save tylerlittlefield/32c1a34961367d05b65ca1b30bfdb0fb to your computer and use it in GitHub Desktop.
Plot the language composition of tidyverse core packages
library(gh)
library(tidyverse)
library(jsonlite)
tidyrepos <- c("ggplot2",
"dplyr",
"tidyr",
"readr",
"purrr",
"tibble",
"stringr",
"forcats")
endpoint_str <- function(repo) glue::glue("/repos/tidyverse/{repo}/languages")
tidylangs <- sapply(tidyrepos, function(x) gh(paste0(endpoint_str(x)))) %>%
toJSON(pretty = TRUE) %>%
fromJSON() %>%
bind_rows() %>%
mutate(repo = tidyrepos) %>%
gather("lang", "bytes", -c("repo")) %>%
drop_na(bytes) %>%
group_by(repo) %>%
mutate(percentage = bytes / sum(bytes, na.rm = TRUE)) %>%
ungroup() %>%
arrange(repo) %>%
print(n = nrow(.))
tidylangs %>%
ggplot(aes(lang, percentage, fill = lang)) +
geom_col(show.legend = FALSE) +
coord_flip() +
labs(x = NULL, y = NULL) +
facet_grid(rows = vars(repo), scales = "free_y") +
scale_y_continuous(labels = scales::percent) +
theme_bw() +
theme(
# text = element_text(family = "ProzaLibre-Regular"),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_blank(),
plot.title = element_text(size = 30, hjust = 0.5)
)
@tylerlittlefield
Copy link
Author

tylerlittlefield commented Nov 27, 2018

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment