library(tidyverse)
## -- Attaching packages -------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.1     v purrr   0.3.2
## v tibble  2.1.3     v dplyr   0.8.3
## v tidyr   0.8.3     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## -- Conflicts ----------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(readr)
library(esquisse)
library(ggplot2)




Accident_LVL_Table <- read_csv("Datasets/Accident_LVL_Table.csv")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   ACCIDENT_NO = col_character(),
##   DATE = col_date(format = ""),
##   LGA = col_character(),
##   ACCIDENTTIME = col_character(),
##   ACCIDENT.TYPE.DESC = col_character(),
##   DAY.WEEK.DESCRIPTION = col_character(),
##   DCA.DESCRIPTION = col_character(),
##   DIRECTORY = col_character(),
##   PAGE = col_character(),
##   GRID_REFERENCE_X = col_character(),
##   LIGHT.CONDITION.DESC = col_character(),
##   ROAD.GEOMETRY.DESC = col_character(),
##   TOTAL_POPULATION = col_logical(),
##   PERSONS.KM2 = col_logical()
## )
## See spec(...) for full column specifications.
## Warning: 188460 parsing failures.
##   row              col           expected actual                              file
## 65513 EDITION          a double             ED35 'Datasets/Accident_LVL_Table.csv'
## 66295 EDITION          a double             ED35 'Datasets/Accident_LVL_Table.csv'
## 67799 TOTAL_POPULATION 1/0/T/F/TRUE/FALSE   -    'Datasets/Accident_LVL_Table.csv'
## 67799 PERSONS.KM2      1/0/T/F/TRUE/FALSE   -    'Datasets/Accident_LVL_Table.csv'
## 67800 TOTAL_POPULATION 1/0/T/F/TRUE/FALSE   -    'Datasets/Accident_LVL_Table.csv'
## ..... ................ .................. ...... .................................
## See problems(...) for more details.
Master_Table <- read_csv("Datasets/Master Table.csv")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   DATE = col_date(format = ""),
##   LGA = col_character(),
##   ACCIDENT_NO = col_character(),
##   VEHICLE_ID = col_character(),
##   PERSON_ID = col_character(),
##   SEX = col_character(),
##   AGE.GROUP = col_character(),
##   INJ.LEVEL.DESC = col_character(),
##   SEATING_POSITION = col_character(),
##   ROAD.USER.TYPE.DESC = col_character(),
##   LICENCE_STATE = col_character(),
##   TAKEN_HOSPITAL = col_character(),
##   ACCIDENTTIME = col_character(),
##   ACCIDENT.TYPE.DESC = col_character(),
##   DAY.WEEK.DESCRIPTION = col_character(),
##   DCA.DESCRIPTION = col_character(),
##   DIRECTORY = col_character(),
##   GRID_REFERENCE_X = col_character(),
##   LIGHT.CONDITION.DESC = col_character(),
##   ROAD.GEOMETRY.DESC = col_character()
##   # ... with 3 more columns
## )
## See spec(...) for full column specifications.
## Warning: 52807 parsing failures.
##   row     col               expected actual                        file
## 19539 EDITION a double                 ED35 'Datasets/Master Table.csv'
## 19540 EDITION a double                 ED35 'Datasets/Master Table.csv'
## 19541 EDITION a double                 ED35 'Datasets/Master Table.csv'
## 27491 EDITION a double                 ED35 'Datasets/Master Table.csv'
## 44635 PAGE    no trailing characters   A    'Datasets/Master Table.csv'
## ..... ....... ...................... ...... ...........................
## See problems(...) for more details.
temp <- Master_Table %>% select(ACCIDENT.TYPE.DESC , LIGHT.CONDITION.DESC , SPEED_ZONE , NO_OF_VEHICLES, AGE.GROUP ,ROAD.GEOMETRY.DESC,SEX,DAY.WEEK.DESCRIPTION)



speed_temp <- temp %>% filter(SPEED_ZONE < 700)
    ggplot(temp) +
    aes(x = ROAD.GEOMETRY.DESC, fill = ACCIDENT.TYPE.DESC) +
    geom_bar(position = "dodge") +
    scale_fill_viridis_d(option = "plasma") +
    theme_minimal()

ggplot(temp) +
    aes(x = ROAD.GEOMETRY.DESC, fill = ACCIDENT.TYPE.DESC) +
    geom_bar(position = "dodge") +
    scale_fill_viridis_d(option = "plasma") +
    coord_flip() +
    theme_minimal()

ggplot(temp) +
    aes(x = ROAD.GEOMETRY.DESC, fill = ACCIDENT.TYPE.DESC) +
    geom_bar(position = "dodge") +
    scale_fill_hue() +
    coord_flip() +
    theme_minimal()

ggplot(temp) +
    aes(x = ROAD.GEOMETRY.DESC, fill = SEX) +
    geom_bar(position = "dodge") +
    scale_fill_hue() +
    theme_gray()

ggplot(temp) +
    aes(x = ROAD.GEOMETRY.DESC) +
    geom_bar(fill = "#8fd175") +
    theme_minimal()

ggplot(temp) +
    aes(x = ROAD.GEOMETRY.DESC, fill = AGE.GROUP) +
    geom_bar(position = "dodge") +
    scale_fill_hue() +
    theme_minimal()

ggplot(temp) +
    aes(x = ROAD.GEOMETRY.DESC, fill = DAY.WEEK.DESCRIPTION) +
    geom_bar(position = "dodge") +
    scale_fill_hue() +
    theme_minimal()

speedage_temp <- speed_temp %>%
    filter(!(AGE.GROUP %in% "unknown"))



ggplot(speedage_temp) +
    aes(x = SPEED_ZONE) +
    geom_histogram(bins = 30L, fill = "#47039f") +
    scale_x_continuous(trans = "log10") +
    theme_gray() +
    facet_wrap(vars(AGE.GROUP))

ggplot(speed_temp) +
    aes(x = SPEED_ZONE) +
    geom_histogram(bins = 30L, fill = "#377eb8") +
    theme_gray()

ggplot(speed_temp) +
    aes(x = SPEED_ZONE, fill = SEX) +
    geom_histogram(bins = 30L) +
    scale_fill_hue() +
    scale_x_continuous(trans = "log10") +
    theme_minimal()

ggplot(speed_temp) +
    aes(x = SPEED_ZONE, fill = SEX) +
    geom_histogram(bins = 30L) +
    scale_fill_hue() +
    scale_x_continuous(trans = "log10") +
    theme_minimal() +
    facet_wrap(vars(ACCIDENT.TYPE.DESC))

ggplot(speed_temp) +
    aes(x = SPEED_ZONE, fill = SEX) +
    geom_histogram(bins = 30L) +
    scale_fill_hue() +
    scale_x_continuous(trans = "log10") +
    theme_minimal() +
    facet_wrap(vars(LIGHT.CONDITION.DESC))

ggplot(speed_temp) +
    aes(x = SPEED_ZONE, fill = SEX) +
    geom_histogram(bins = 30L) +
    scale_fill_hue() +
    scale_x_continuous(trans = "log10") +
    theme_minimal() +
    facet_wrap(vars(NO_OF_VEHICLES))

ggplot(speed_temp) +
    aes(x = SPEED_ZONE, fill = SEX) +
    geom_histogram(bins = 30L) +
    scale_fill_hue() +
    scale_x_continuous(trans = "log10") +
    theme_minimal() +
    facet_wrap(vars(ROAD.GEOMETRY.DESC))

ggplot(speed_temp) +
    aes(x = SPEED_ZONE, fill = SEX) +
    geom_histogram(bins = 30L) +
    scale_fill_hue() +
    scale_x_continuous(trans = "log10") +
    theme_minimal() +
    facet_wrap(vars(DAY.WEEK.DESCRIPTION))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE) +
 geom_histogram(bins = 30L, fill = "#0c4c8a") +
    scale_x_continuous(trans = "log10") +
    theme_minimal() +
 facet_wrap(vars(SEX))

library(ggplot2)

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ACCIDENT.TYPE.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal()

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ACCIDENT.TYPE.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(LIGHT.CONDITION.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ACCIDENT.TYPE.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(NO_OF_VEHICLES))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ACCIDENT.TYPE.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(AGE.GROUP))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ACCIDENT.TYPE.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(ROAD.GEOMETRY.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ACCIDENT.TYPE.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(SEX))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ACCIDENT.TYPE.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(DAY.WEEK.DESCRIPTION))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = LIGHT.CONDITION.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal()

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = LIGHT.CONDITION.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(ACCIDENT.TYPE.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = LIGHT.CONDITION.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(NO_OF_VEHICLES))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = LIGHT.CONDITION.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(AGE.GROUP))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = LIGHT.CONDITION.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(ROAD.GEOMETRY.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = LIGHT.CONDITION.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(SEX))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = LIGHT.CONDITION.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 theme_minimal() +
 facet_wrap(vars(DAY.WEEK.DESCRIPTION))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE) +
 geom_histogram(bins = 30L, fill = "#0c4c8a") +
 theme_minimal() +
 facet_wrap(vars(NO_OF_VEHICLES))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = AGE.GROUP) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(ACCIDENT.TYPE.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = AGE.GROUP) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(LIGHT.CONDITION.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = AGE.GROUP) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal()

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = AGE.GROUP) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(NO_OF_VEHICLES))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = AGE.GROUP) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(ROAD.GEOMETRY.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = AGE.GROUP) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(SEX))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = AGE.GROUP) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(DAY.WEEK.DESCRIPTION))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ROAD.GEOMETRY.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(ACCIDENT.TYPE.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ROAD.GEOMETRY.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(LIGHT.CONDITION.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ROAD.GEOMETRY.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(NO_OF_VEHICLES))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ROAD.GEOMETRY.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(AGE.GROUP))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ROAD.GEOMETRY.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(SEX))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ROAD.GEOMETRY.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(DAY.WEEK.DESCRIPTION))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = DAY.WEEK.DESCRIPTION) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(ACCIDENT.TYPE.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = DAY.WEEK.DESCRIPTION) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(LIGHT.CONDITION.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = DAY.WEEK.DESCRIPTION) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(NO_OF_VEHICLES))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = DAY.WEEK.DESCRIPTION) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(AGE.GROUP))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = DAY.WEEK.DESCRIPTION) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(ROAD.GEOMETRY.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = DAY.WEEK.DESCRIPTION) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(SEX))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ACCIDENT.TYPE.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal()

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = LIGHT.CONDITION.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal()

ggplot(speed_temp) +
 aes(x = SPEED_ZONE) +
 geom_histogram(bins = 30L, fill = "#0c4c8a") +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(ACCIDENT.TYPE.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE) +
 geom_histogram(bins = 30L, fill = "#0c4c8a") +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(LIGHT.CONDITION.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE) +
 geom_histogram(bins = 30L, fill = "#0c4c8a") +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(NO_OF_VEHICLES))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE) +
 geom_histogram(bins = 30L, fill = "#0c4c8a") +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(AGE.GROUP))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE) +
 geom_histogram(bins = 30L, fill = "#0c4c8a") +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(ROAD.GEOMETRY.DESC))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE) +
 geom_histogram(bins = 30L, fill = "#0c4c8a") +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(SEX))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE) +
 geom_histogram(bins = 30L, fill = "#0c4c8a") +
 scale_x_continuous(trans = "log10") +
 theme_minimal() +
 facet_wrap(vars(DAY.WEEK.DESCRIPTION))

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = DAY.WEEK.DESCRIPTION) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal()

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = SEX) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal()

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = ROAD.GEOMETRY.DESC) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal()

ggplot(speed_temp) +
 aes(x = SPEED_ZONE, fill = AGE.GROUP) +
 geom_histogram(bins = 30L) +
 scale_fill_hue() +
 scale_x_continuous(trans = "log10") +
 theme_minimal()