HSIS Data [Sample]
library(ggplot2)
library(scales)
library(plyr)
library(psych)
describe(ca_1)
## vars n mean sd median trimmed mad min max
## desg_spd 1 243 47.18 13.01 50 47.26 22.24 25 65
## aadt 2 243 20294.91 9253.54 19655 19369.40 4084.56 4900 51000
## medwid 3 243 6.44 7.45 6 5.48 8.90 0 46
## med_type1* 4 243 3.18 1.17 4 3.25 1.48 1 5
## range skew kurtosis se
## desg_spd 40 -0.13 -1.46 0.83
## aadt 46100 1.33 2.70 593.61
## medwid 46 1.22 2.49 0.48
## med_type1* 4 -0.43 -1.04 0.07
describe(il_1)
## vars n mean sd median trimmed mad min max
## spd_limt 1 491 36.56 6.78 35 35.79 7.41 30 55
## aadt 2 491 27002.24 11555.33 34700 28251.91 2372.16 5300 39800
## medwid 3 491 6.67 12.29 0 3.69 0.00 0 65
## med_type1* 4 491 2.35 1.04 3 2.34 0.00 1 4
## range skew kurtosis se
## spd_limt 25 0.98 0.16 0.31
## aadt 34500 -0.63 -1.33 521.48
## medwid 65 2.90 9.33 0.55
## med_type1* 3 -0.33 -1.44 0.05
describe(mn_1)
## vars n mean sd median trimmed mad min max
## speed 1 358 39.65 10.77 40 39.50 14.83 0 70
## aadt 2 358 26347.45 11731.71 23700 25635.35 13195.14 6200 55220
## medwid 3 358 8.13 15.12 0 4.85 0.00 0 51
## med_type1* 4 358 2.94 0.59 3 2.95 0.00 1 4
## range skew kurtosis se
## speed 70 -0.45 1.54 0.57
## aadt 49020 0.46 -1.10 620.04
## medwid 51 1.60 0.93 0.80
## med_type1* 3 -0.73 2.05 0.03
library(scales)
ca_2 <- ca_1[c(4)]
ca_3 = count(ca_2)
il_2 <- il_1[c(4)]
il_3 = count(il_2)
mn_2 <- mn_1[c(4)]
mn_3 = count(mn_2)
ca_a <- ggplot(ca_1, aes(x=factor(desg_spd)))
il_a <- ggplot(il_1, aes(x=factor(spd_limt)))
mn_a <- ggplot(mn_1, aes(x=factor(speed)))
ca_b <- ggplot(ca_1, aes(x=aadt))
il_b <- ggplot(il_1, aes(x=aadt))
mn_b <- ggplot(mn_1, aes(x=aadt))
ca_c <- ggplot(ca_1, aes(x=factor(medwid)))
il_c <- ggplot(il_1, aes(x=factor(medwid)))
mn_c <- ggplot(mn_1, aes(x=factor(medwid)))
ca_e <- ggplot(ca_1, aes(x=med_type1))
il_e <- ggplot(il_1, aes(x=med_type1))
mn_e <- ggplot(mn_1, aes(x=med_type1))
ca_d <- ggplot(ca_3, aes(x=reorder(med_type1, -freq), y= freq))
il_d <- ggplot(il_3, aes(x=reorder(med_type1, -freq), y= freq))
mn_d <- ggplot(mn_3, aes(x=reorder(med_type1, -freq), y= freq))
m1 <- ca_a+ geom_bar(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#046C9A") +
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="Speed Limit (mph) \n (a)", y="Percentage") +
theme(text = element_text(size=30)) + ggtitle("California")+ theme_bw()
m2 <- il_a + geom_bar(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#B40F20") +
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="Speed Limit (mph) \n (b)", y="") +
theme(text = element_text(size=30)) + ggtitle("Illinois")+ theme_bw()
m3 <- mn_a + geom_bar(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#CEAB07") +
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="Speed Limit (mph) \n (c)", y="") +
theme(text = element_text(size=30)) + ggtitle("Minnesota")+ theme_bw()
m4 <- ca_b+ geom_histogram(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#046C9A",
breaks=c(0, 10000, 20000, 30000, 40000, 50000, 60000))+
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="AADT (vph) \n (d)", y="Percentage") +
theme(text = element_text(size=30)) + theme_bw()
m5 <- il_b + geom_histogram(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#B40F20",
breaks=c(0, 10000, 20000, 30000, 40000, 50000, 60000))+
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="AADT (vph) \n (e)", y="") +
theme(text = element_text(size=30)) + theme_bw()
m6 <- mn_b + geom_histogram(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#CEAB07",
breaks=c(0, 10000, 20000, 30000, 40000, 50000, 60000))+
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="AADT (vph) \n (f)", y="") +
theme(text = element_text(size=30)) + theme_bw()
m7 <- ca_c + geom_bar(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#046C9A") +
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="Median width (ft.) \n (g)", y="Percentage") +
theme(text = element_text(size=30)) + theme_bw()
m8 <- il_c + geom_bar(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#B40F20") +
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="Median width (ft.) \n (h)", y="") +
theme(text = element_text(size=30)) + theme_bw()
m9 <- mn_c + geom_bar(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#CEAB07") +
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="Median width (ft.) \n (i)", y="") +
theme(text = element_text(size=30)) + theme_bw()
m10 <- ca_e+ theme_bw()+ geom_bar(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#046C9A") +
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="Median Types \n (j)", y="Percentage") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
m11 <- il_e+theme_bw()+ geom_bar(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#B40F20") +
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="Median Types \n (k)", y="") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
m12 <- mn_e+theme_bw()+ geom_bar(aes(y = (..count..)/sum(..count..)), colour = "#4E2A1E", width=1, fill = "#CEAB07") +
scale_y_continuous(labels=percent, limits=c(0,0.75))+
labs(x="Median Types \n (l)", y="") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
library(grid)
grid.newpage()
pushViewport(viewport(layout = grid.layout(4, 3)))
vplayout <- function(x, y)
viewport(layout.pos.row = x, layout.pos.col = y)
print(m1, vp = vplayout(1, 1))
print(m2, vp = vplayout(1, 2))
print(m3, vp = vplayout(1, 3))
print(m4, vp = vplayout(2, 1))
print(m5, vp = vplayout(2, 2))
print(m6, vp = vplayout(2, 3))
print(m7, vp = vplayout(3, 1))
print(m8, vp = vplayout(3, 2))
print(m9, vp = vplayout(3, 3))
print(m10, vp = vplayout(4, 1))
print(m11, vp = vplayout(4, 2))
print(m12, vp = vplayout(4, 3))
