Created
January 30, 2015 14:13
-
-
Save klmr/ed3b5dbcb8b6cc6fbab3 to your computer and use it in GitHub Desktop.
Create top 20 list of your Stack Overflow tag views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
options(stringsAsFactors = FALSE) | |
library(dplyr) | |
library(ggplot2) | |
library(jsonlite) | |
# Usage: | |
# ./tagviews.r datafile.json output.png | |
args = commandArgs(TRUE) | |
filename = args[1] | |
filecontents = fromJSON(readChar(filename, file.info(filename)$size)) | |
tags = filecontents$Data$TagView %>% | |
do.call(rbind, .) %>% | |
as.data.frame() %>% | |
add_rownames('Tag') %>% | |
as_data_frame() %>% | |
rename(Count = V1) | |
top20 = tags %>% top_n(20) %>% arrange(Count) | |
on.exit(dev.off()) | |
output = args[2] | |
png(output) | |
ggplot(top20, aes(x = factor(Tag, Tag), y = Count)) + | |
geom_bar(stat = 'identity') + | |
coord_flip() + | |
scale_x_discrete(name = 'Tag') + | |
theme_bw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment