public
Last active

Compare Titles of the U.S. Code by some common measures.

  • Download Gist
plot_title_comparisons.R
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
# @date 20130818
# @author Bommarito Consulting, LLC; michael@bommaritollc.com
# @page http://bommaritollc.com/?p=1067
 
# Load libraries
library(ggplot2)
 
# Load data from git master
title_data <- read.csv('https://raw.github.com/mjbommar/us-code-complexity/master/results/table_data.csv',
header=T,
colClasses=c('factor', rep('numeric', 14)))
names(title_data)[2:5] <- c('ElementCount', 'SuperSectionCount', 'SectionCount', 'SubSectionCount')
 
# Plot descending word count
token_title_data <- title_data[order(-title_data$Tokens), c('Title', 'Tokens')]
token_title_data$TitleN <- reorder(token_title_data$Title, token_title_data$Tokens)
ggplot(token_title_data, aes(x=TitleN, y=Tokens)) +
geom_bar(stat="identity") +
scale_y_continuous("Tokens") +
scale_x_discrete("Title") +
coord_flip()
 
# Plot descending words per section count
tps_title_data <- title_data[order(-title_data$SectionCount), c('Title', 'TokensPerSection')]
tps_title_data$TitleN <- reorder(tps_title_data$Title, tps_title_data$TokensPerSection)
ggplot(tps_title_data, aes(x=TitleN, y=TokensPerSection)) +
geom_bar(stat="identity") +
scale_y_continuous("TokensPerSection") +
scale_x_discrete("Title") +
coord_flip()
 
# Plot descending element count
element_title_data <- title_data[order(-title_data$ElementCount), c('Title', 'ElementCount')]
element_title_data$TitleN <- reorder(element_title_data$Title, element_title_data$ElementCount)
ggplot(element_title_data, aes(x=TitleN, y=ElementCount)) +
geom_bar(stat="identity") +
scale_y_continuous("ElementCount") +
scale_x_discrete("Title") +
coord_flip()
 
# Plot descending section count
element_title_data <- title_data[order(-title_data$SectionCount), c('Title', 'SectionCount')]
element_title_data$TitleN <- reorder(element_title_data$Title, element_title_data$SectionCount)
ggplot(element_title_data, aes(x=TitleN, y=SectionCount)) +
geom_bar(stat="identity") +
scale_y_continuous("SectionCount") +
scale_x_discrete("Title") +
coord_flip()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.