Skip to content

Instantly share code, notes, and snippets.

@low-decarie
Last active September 26, 2016 20:47
Show Gist options
  • Save low-decarie/6b2cd953721954b81453cc0362fb1536 to your computer and use it in GitHub Desktop.
Save low-decarie/6b2cd953721954b81453cc0362fb1536 to your computer and use it in GitHub Desktop.
#Creates a histogram of publications per year from text currently in the clipboard. Must be edited for mac or windows.
require(stringr)
require(ggplot2)
#on windows
#text <- readLines("clipboard")
#for a mac
text <- readLines(textConnection(system("pbpaste",intern=TRUE)))
years <- as.numeric(na.omit(unlist(str_extract_all(text,"(19|20)[0-9][0-9]"))))
years <- years[years<2020]
years <- years[years>1950]
year_table <- data.frame(table(years))
p <- ggplot(data=year_table,
aes(x=as.numeric(as.character(years)),
y=Freq))+
geom_bar(stat="identity")+
xlab("Years")+
ylab("Number of articles")
print(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment