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)
Vehicle_Data_Cleaned <- read_csv("Datasets/latest.csv")
## Parsed with column specification:
## cols(
## .default = col_double(),
## ACCIDENT_NO = col_character(),
## VEHICLE_ID = col_character(),
## INITIAL_DIRECTION = col_character(),
## ROAD.SURFACE.TYPE.DESC = col_character(),
## REG_STATE = col_character(),
## VEHICLE_BODY_STYLE = col_character(),
## VEHICLE_MAKE = col_character(),
## VEHICLE_MODEL = col_character(),
## VEHICLE_POWER = col_logical(),
## VEHICLE.TYPE.DESC = col_character(),
## CONSTRUCTION_TYPE = col_character(),
## FUEL_TYPE = col_character(),
## CUBIC_CAPACITY = col_number(),
## FINAL_DIRECTION = col_character(),
## TRAILER_TYPE = col_character(),
## VEHICLE_COLOUR_1 = col_character(),
## VEHICLE_COLOUR_2 = col_character(),
## INITIAL_IMPACT = col_character(),
## TRAFFIC.CONTROL.DESC = col_character(),
## DATE = col_character()
## # ... with 20 more columns
## )
## See spec(...) for full column specifications.
## Warning: 290774 parsing failures.
## row col expected actual file
## 102200 EDITION a double ED35 'Datasets/latest.csv'
## 102201 EDITION a double ED35 'Datasets/latest.csv'
## 103402 EDITION a double ED35 'Datasets/latest.csv'
## 103403 EDITION a double ED35 'Datasets/latest.csv'
## 105707 TOTAL_POPULATION 1/0/T/F/TRUE/FALSE - 'Datasets/latest.csv'
## ...... ................ .................. ...... .....................
## See problems(...) for more details.
tort <- Vehicle_Data_Cleaned %>% mutate(Road_geometry =ifelse(ROAD.GEOMETRY.DESC %in% c("Cross intersection","Multiple intersection","T intersection","Y intersection"),"Intersection",ifelse(ROAD.GEOMETRY.DESC %in% c("Not at intersection"),"Not intersection","other")))
tort1 <- tort %>% mutate(Light_Condition =ifelse(LIGHT.CONDITION.DESC %in% c("Dark No street lights", "Dark Street lights off","Dark Street lights on","Dark Street lights unknown"),"Night",ifelse(LIGHT.CONDITION.DESC %in% c("Day"),"Day",ifelse(LIGHT.CONDITION.DESC %in% c("Dusk/Dawn"),"Dusk/Dawn","other"))))
tort2 <- tort1 %>% mutate(Rainfall = ifelse(RAINFALL >= 1.5,"WET" ,"DRY"))
temp <- tort2 %>% select(SEVERITY,Rainfall,RAINFALL,Light_Condition,Road_geometry,ACCIDENT.TYPE.DESC,SPEED_ZONE,NO_OF_VEHICLES,ROAD_TYPE,DRIVER_AGE,DRIVER_SEX,VEHICLE_YEAR_MANUF,VEHICLE.TYPE.DESC)
temprg <- temp %>%
filter(!(Road_geometry %in% "other"))
library(ggplot2)
ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Rainfall) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic()

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Rainfall) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(SEVERITY))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = DRIVER_SEX) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic()

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Road_geometry) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic()

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Road_geometry) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(SEVERITY))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Road_geometry) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(DRIVER_SEX))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Road_geometry) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(DRIVER_AGE))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Road_geometry) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(Rainfall))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Road_geometry) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(ACCIDENT.TYPE.DESC))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Road_geometry) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(Light_Condition))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = DRIVER_SEX) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(Light_Condition))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = DRIVER_SEX) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(ACCIDENT.TYPE.DESC))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = DRIVER_SEX) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(NO_OF_VEHICLES))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = DRIVER_SEX) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(Rainfall))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = DRIVER_SEX) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic() +
facet_wrap(vars(Road_geometry))

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = ACCIDENT.TYPE.DESC) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic()

ggplot(temp) +
aes(x = VEHICLE.TYPE.DESC, fill = Rainfall) +
geom_bar(position = "dodge") +
scale_fill_hue() +
theme_classic()

ggplot(temp) +
aes(x = SEVERITY, fill = VEHICLE.TYPE.DESC) +
geom_bar(position="dodge") +
scale_fill_hue() +
theme_minimal()
