Browse Source

Exploratory data analysis

Petra Lamborn 4 years ago
parent
commit
3e818c994e
4 changed files with 10 additions and 1 deletions
  1. BIN
      Missing2018.png
  2. BIN
      OpenRoadSHSeverity.png
  3. BIN
      Severity.png
  4. 10
    1
      expl.R

BIN
Missing2018.png View File


BIN
OpenRoadSHSeverity.png View File


BIN
Severity.png View File


+ 10
- 1
expl.R View File

@@ -1,9 +1,11 @@
1 1
 # Exploration on data
2
+# Export images 700x400
2 3
 
3 4
 # Libraries
4 5
 library(ggplot2)
5 6
 library(dplyr)
6 7
 library(RColorBrewer)
8
+library(scales)
7 9
 
8 10
 # Load data from Rdata file
9 11
 load("crashdata.Rdata")
@@ -38,7 +40,8 @@ vehtab
38 40
 
39 41
 # Graph crash severity
40 42
 ggplot(dat) + geom_bar(aes(x=CRASH_SEV), fill=NA, col="black") +
41
-  theme_classic() + labs(x = "Crash severity", y = "Number of crashes")
43
+  theme_classic() + labs(x = "Crash severity", y = "Number of crashes") +
44
+  scale_y_continuous(labels = scales::comma)
42 45
 
43 46
 # Not all openroad crashes are on state highways
44 47
 table(dat$URBAN, dat$CRASH_SH_DESC)
@@ -60,3 +63,9 @@ ggplot(rurhwy) +
60 63
                       labels = c("Single vehicle", "All other categories")) +
61 64
   scale_x_discrete("Severity", labels = c("Not", "Moderate", "Severe", "Fatal")) +
62 65
   theme_classic() + theme(legend.position = "right")
66
+
67
+rurtype <- as.data.frame.matrix(table(rurhwy$CRASH_SEV, rurhwy$MULTI_VEH))
68
+rurtypefrac <- rurtype / rowSums(rurtype)
69
+rurtypefrac["Single vehicle"]
70
+
71
+colSums(rurtype)/sum(rurtype)