Skip to content

Instantly share code, notes, and snippets.

@sckott
Last active July 2, 2016 01:32
Show Gist options
  • Save sckott/10473818 to your computer and use it in GitHub Desktop.
Save sckott/10473818 to your computer and use it in GitHub Desktop.

Install package

install_github("ropensci/git2r")

Load libary

library("git2r")
library("plyr")

Repositories with activity during hackathon

repos <- c("ropensci/git2r", "ropensci/docs", "ropensci/testdat", "ropensci/apistatus", 
    "ropensci/reproducibility-guide", "ropensci/EML", "ropensci/togeojson", 
    "ropensci/rfigshare", "ropensci/dependencies", "ropensci/plotly", "ropensci/paleobioDB", 
    "ropensci/taxize", "ropensci/ecoretriever", "ropensci/hackathon", "ropensci/elife", 
    "ramnathv/rMaps", "ScienceToolbox/code_citations")

Clone repositories

hackathon <- lapply(repos, function(repo) {
    clone(paste0("https://github.com/", repo, ".git"), paste0("hackathon/", 
        repo))
})

Get commit data

df <- lapply(hackathon, function(repo) {
    cbind(basename(workdir(repo)), contributions(repo, breaks = "day", by = "author"))
})
df <- do.call("rbind", df)
df <- df[df$when > as.Date("2014-03-30") & df$when < as.Date("2014-04-02"), ]
names(df)[1] <- "repo"

Synonymise authors

res <- gsub("EDiLD", "Eduard Szöcs", df$author)
res <- gsub("davharris", "David J. Harris", res)
res <- gsub("Hilary|Hilary Parker", "Hilary Parker", res)
res <- gsub("iamciera", "Ciera Martinez", res)
res <- gsub("Jeff Hollister", "Jeffrey W. Hollister", res)
res <- gsub("jmollica", "Jay Mollica", res)
res <- gsub("Jeff Hollister|Jeffrey W Hollister", "Jeffrey W. Hollister", res)
res <- gsub("anyab", "Anya Bida", res)
res <- gsub("LucianoFSgarbi", "Luciano F. Sgarbi", res)
res <- gsub("mfenner", "Martin Fenner", res)
res <- gsub("Sara_Varela", "Sara Varela", res)
df$author <- res

df <- ddply(df, .(repo, author), summarise, n = sum(n)) # summarise across dates

Plot

library(ggplot2)
ggplot(df, aes(repo, author)) + geom_tile(aes(fill = n), colour = "white", binwidth = 3) + 
    scale_fill_gradient(low = "white", high = "steelblue") + theme_grey(base_size = 16) + 
    labs(x = "", y = "") + scale_x_discrete(expand = c(0, 0)) + scale_y_discrete(expand = c(0, 
    0)) + theme(axis.ticks = element_blank(), axis.text.x = element_text(size = 12, 
    hjust = 1, colour = "grey50", angle = 45), panel.grid.major = element_blank(), 
    panel.grid.minor = element_blank(), panel.border = element_blank(), panel.background = element_rect(fill = "#F8F8F8", 
        colour = NA))

Install package
```{r eval=FALSE}
install_github("ropensci/git2r")
```
Load libary
```{r}
library("git2r")
library("plyr")
```
Repositories with activity during hackathon
```{r}
repos <- c('ropensci/git2r', 'ropensci/docs', 'ropensci/testdat', 'ropensci/apistatus','ropensci/reproducibility-guide', 'ropensci/EML', 'ropensci/togeojson','ropensci/rfigshare', 'ropensci/dependencies', 'ropensci/plotly','ropensci/paleobioDB','ropensci/taxize', 'ropensci/ecoretriever','ropensci/hackathon','ropensci/elife','ramnathv/rMaps','ScienceToolbox/code_citations')
```
Clone repositories
```{r cache=TRUE}
hackathon <- lapply(repos, function(repo) {
clone(paste0('https://github.com/', repo, '.git'),
paste0('hackathon/', repo))
})
```
Get commit data
```{r cache=TRUE}
df <- lapply(hackathon, function(repo) {
cbind(basename(workdir(repo)), contributions(repo, breaks='day', by='author'))
})
df <- do.call('rbind', df)
df <- df[df$when > as.Date('2014-03-30') & df$when < as.Date('2014-04-02'),]
names(df)[1] <- 'repo'
```
Synonymise authors
```{r}
res <- gsub("EDiLD", "Eduard Szöcs", df$author)
res <- gsub("davharris", "David J. Harris", res)
res <- gsub("Hilary|Hilary Parker", "Hilary Parker", res)
res <- gsub("iamciera", "Ciera Martinez", res)
res <- gsub("Jeff Hollister", "Jeffrey W. Hollister", res)
res <- gsub("jmollica", "Jay Mollica", res)
res <- gsub("Jeff Hollister|Jeffrey W Hollister", "Jeffrey W. Hollister", res)
res <- gsub("anyab", "Anya Bida", res)
res <- gsub("LucianoFSgarbi", 'Luciano F. Sgarbi', res)
res <- gsub("mfenner", 'Martin Fenner', res)
res <- gsub("Sara_Varela", "Sara Varela", res)
df$author <- res
df <- ddply(df, .(repo, author), summarise, n = sum(n)) # summarise across dates
```
Plot
```{r}
library(ggplot2)
ggplot(df, aes(repo, author)) +
geom_tile(aes(fill = n), colour = "white", binwidth = 3) +
scale_fill_gradient(low = "white", high = "steelblue") +
theme_grey(base_size = 16) +
labs(x = "", y = "") +
scale_x_discrete(expand = c(0,0)) +
scale_y_discrete(expand = c(0, 0)) +
theme(axis.ticks = element_blank(),
axis.text.x = element_text(size = 12, hjust = 1, colour = "grey50", angle = 45),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_rect(fill = "#F8F8F8",
colour = NA))
```
@karthik
Copy link

karthik commented Apr 11, 2014

Nice work! Where is this post headed?

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