Skip to content

Instantly share code, notes, and snippets.

@ajstewartlang
Last active November 12, 2019 15:44
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 ajstewartlang/1c1993ee6286fef3ceeaa077ba07c351 to your computer and use it in GitHub Desktop.
Save ajstewartlang/1c1993ee6286fef3ceeaa077ba07c351 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(ggthemes)
cran_code <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-11-12/loc_cran_packages.csv")
# Plot 1 ####
cran_code %>%
group_by(language) %>%
summarise(n = n()) %>%
arrange(-n) %>%
top_n(10, n) %>%
left_join(cran_code, by = "language") %>%
mutate(prop_comments = (comment / (code + comment + blank)) * 100) %>%
group_by(language) %>%
summarise(mean_comments_percent = mean(prop_comments)) %>%
ggplot(aes(x = fct_reorder(language, mean_comments_percent, median),
y = mean_comments_percent,
fill = language)) +
geom_col() +
coord_flip() +
guides(fill = FALSE) +
labs(title = "Mean % of comments in package scripts",
subtitle = "10 most commonly used languages in packages on CRAN",
x = NULL,
y = "Mean % of script lines which are comments") +
scale_fill_viridis(option = "A", discrete = TRUE) +
theme_economist() +
theme(text = element_text(size = 12))
# Plot 2 ####
cran_code %>%
group_by(language) %>%
summarise(total = sum(code), med = median(code)) %>%
arrange(-total) %>%
top_n(10, total) %>%
inner_join(cran_code, by = "language") %>%
group_by(language) %>%
ggplot(aes(x = fct_reorder(language, -med), y = code, colour = language)) +
geom_jitter(width = .1, alpha = .01, size = 5) +
stat_summary(fun.y = median, fun.ymin = min, fun.ymax = max, colour = "black", alpha = .3) +
scale_y_log10() +
theme_economist() +
theme(axis.text.x = element_text(angle = 90, hjust = 0)) +
theme(text = element_text(size = 12)) +
labs(title = "Lines of code (log) by language in packages on CRAN",
subtitle = "Top 10 languges determined by total lines of code in each language",
x = NULL,
y = "Number of lines of code (log)") +
guides(colour = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment