Skip to content

Instantly share code, notes, and snippets.

@jabranham
Last active March 24, 2019 16:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jabranham/887495eaf029680316fecb374f0723e0 to your computer and use it in GitHub Desktop.
Save jabranham/887495eaf029680316fecb374f0723e0 to your computer and use it in GitHub Desktop.
analyze-bib-file
library(tidyverse)
library(bibtex)
theme_set(theme_minimal())
## You'll need to modify the next line to wherever your bib file is
entries <- read.bib("~/Dropbox/bibliography/references.bib")
lentries <- length(entries)
years <- list(lentries)
type <- list(lentries)
journals <- list(lentries)
for (i in 1:length(entries)) {
years[i] <- entries[[i]]$year
type[i] <- attributes(unclass(entries)[[i]])$bibtype
if (type[i] == "Article"){
journals[i] <- entries[i]$journal
} else journals[i] <- NA
}
entries <- data.frame(year = as.numeric(unlist(years)),
type = unlist(type),
journal = unlist(journals))
## Make a graph of year vs count, but exclude years before 1950
entries %>%
filter(year > 1950) %>%
ggplot(aes(year)) +
geom_bar() +
labs(x = "Year",
y = "Count")
## Graph of type (article, book, etc)
entries %>%
ggplot(aes(type)) +
geom_bar()
## Graph of count per journal
entries %>%
group_by(journal) %>%
summarize(n = n()) %>%
arrange(desc(n)) %>%
mutate(journal = factor(journal, levels = .$journal[order(.$n)])) %>%
filter(n > 4, !is.na(journal)) %>%
ggplot(aes(journal, n)) +
geom_bar(stat = "identity") +
labs(x = "Journal",
y = "Count") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
@ojmarcelino
Copy link

great, it will be nicer to show a table version of the data

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