#imports
library(ggplot2)
library(trelliscopejs)
## Warning: package 'trelliscopejs' was built under R version 4.4.3
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.4 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
#importing my dataset
library(readr)
accident_prediction_india <- read_csv("accident_prediction_india.csv")
## Rows: 298 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (15): State Name, City Name, Month, Day of Week, Accident Severity, Veh...
## dbl (6): Year, Number of Vehicles Involved, Number of Casualties, Number o...
## time (1): Time of Day
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Making my cognostic by making a true false column that shows if the weather was optimal
accident_prediction_india$poor_vis <- accident_prediction_india$`Weather Conditions` %in% c("Foggy", "Hazy", "Rainy", "Stormy")
#Creating the plot
accident_prediction_india %>%
ggplot(aes(x = `Accident Severity`, fill = poor_vis)) +
geom_bar(color = "black") +
scale_fill_manual(
values = c(`TRUE` = "red", `FALSE` = "steelblue"),
labels = c(`TRUE` = "Poor Visibility", `FALSE` = "Clear")
) +
labs(fill = "Visibility Condition") +
#Using trelliscope to facet the histograms by weather condition
facet_trelliscope(
~ `Weather Conditions`,
ncol = 3,
nrow = 2,
name = "Severity_of_Accident_by_Weather",
path = "trelliscope",
as_plotly = "False"
)
## using data from the first layer
## Removing the following cognostics that are all NA: poor_vis
My data set contains information about crashes within India. When I originally pulled the data from Kaggle, it had 3000 rows. Before I pulled it in to this project, I truncated it down to the first 300.
I decided to make a histogram showing the distribution of the different severity of accidents. I thought this would be interesting to see how severe accidents are within India.
I then used trelliscope to facet the histograms by different types of weather. Doing this, you can not only see the different counts of how many accidents happened in each weather type, but you are also able to see how severe accidents are based on different weather patterns.
I am using the condition of the weather as the cognostic data. I am labeling clear weather as blue and bad weather as red.