Last active
August 29, 2015 13:56
-
-
Save blackfist/8909836 to your computer and use it in GitHub Desktop.
Simple bar chart of vcdb data using Jay's veris package
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
library(verisr) | |
library(ggplot2) | |
# Load the data | |
vcdb.dir <- "../vcdb/data/json" | |
vcdb <- json2veris(vcdb.dir) | |
# Filter out the Unknowns | |
filt <- !getfilter(vcdb, list("action.hacking.variety"="Unknown")) | |
# Get the enumeration I'm interested in | |
hacking.variety <- getenum(vcdb,'action.hacking.variety', filter=filt, add.freq=T) | |
# I only want the top five results | |
hvrev <- head(hacking.variety, 5) | |
# This gives me a percentage displayed for each value | |
hvrev$text <- paste0(hvrev$freq*100, "%") | |
# Now plot that sucker. Since I'm doing a horizontal chart I have to | |
# put the x-label into the ylab. That's messed up, R. | |
hv <- ggplot(hvrev, aes(x = enum, y = freq, label=text)) | |
hv <- hv + geom_bar(stat = "identity", fill = "#ED1C24") # stat=identity is necessary for horizontal bar chart | |
hv <- hv + geom_text(hjust=1) | |
hv <- hv + coord_flip() + theme_bw() # coord_flip is what makes it a horizontal chart | |
hv <- hv + labs(title='VCDB Hacking Variety (Unknowns removed)') + ylab("Frequency") + xlab("") | |
print(hv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment