knitr::opts_chunk$set(echo = TRUE)
library("magrittr")
library("dplyr")
library("tibble")
library("ggplot2")
library("tidyr")
library("forcats")

Let us first have a look at who comitted to this repository:

log %>%
group_by(author_name) %>%
  count() %>%
  arrange(desc(n))

Next, we want to see which files were contained in most commits:

log %>%
  unnest(nested) %>% # unnest the tibble
  mutate(changed_file = fct_infreq(fct_lump(changed_file, n = 10))) %>%
  filter(changed_file != "Other") %>%
  ggplot(aes(x = changed_file)) + geom_bar() + coord_flip() + 
  theme_minimal()

We can also easily get a visual overview of the number of insertions & deletions in commits over time:

commit.dat <- data.frame(
    edits = rep(c("Insertions", "Deletions"), each = nrow(log)),
    commit = rep(1:nrow(log), 2),
    count = c(log$total_insertions, -log$total_deletions))

ggplot(commit.dat, aes(x = commit, y = count, fill = edits)) + 
  geom_bar(stat = "identity", position = "identity") +
  theme_minimal()

Or the number of commits broken down by day of the week:

log %>%
  mutate(weekday = factor(weekday, c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"))) %>% 
  ggplot(aes(x = weekday)) + geom_bar() + 
  theme_minimal()

Or how the line number of the files in the directory R changed.

lines <- log %>%
  unnest() %>%
  add_line_history()

r_files <- grep("^R/", lines$changed_file, value = TRUE)

if (length(r_files) > 0) {
  to_plot <- lines %>%
  filter(changed_file %in% r_files)
ggplot(to_plot, aes(x = date, y = current_lines)) + 
  geom_step() + 
  scale_y_continuous(name = "Number of Lines", limits = c(0, NA)) + 
  facet_wrap(~changed_file, scales = "free_y")

} else {
  print("No R/ directory found.")
}


lorenzwalthert/gitsum documentation built on Jan. 17, 2021, 9:34 p.m.