spc_tbl_ [192,286 × 38] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
$ accident_index : chr [1:192286] "2020010219808" "2020010220496" "2020010228005" "2020010228006" ...
$ accident_year : int [1:192286] 2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 ...
$ accident_reference : chr [1:192286] "010219808" "010220496" "010228005" "010228006" ...
$ location_easting_osgr : int [1:192286] 521389 529337 526432 538676 529324 537193 539764 536115 530876 529718 ...
$ location_northing_osgr : int [1:192286] 175144 176237 182761 184371 181286 177105 179234 182297 191335 192342 ...
$ longitude : int [1:192286] NA NA NA NA NA NA NA NA NA NA ...
$ latitude : int [1:192286] NA NA NA NA NA NA NA NA NA NA ...
$ police_force : chr [1:192286] "Metropolitan Police" "Metropolitan Police" "Metropolitan Police" "Metropolitan Police" ...
$ accident_severity : chr [1:192286] "Slight" "Slight" "Slight" "Serious" ...
$ number_of_vehicles : chr [1:192286] "1" "1" "1" "1" ...
$ number_of_casualties : chr [1:192286] "1" "2" "1" "1" ...
$ date : Date[1:192286], format: "2020-02-04" "2020-04-27" ...
$ day_of_week : chr [1:192286] "Tuesday" "Monday" "Wednesday" "Wednesday" ...
$ time : chr [1:192286] "09:00" "13:55" "01:25" "01:50" ...
$ local_authority_district : chr [1:192286] "Wandsworth" "Lambeth" "Westminster" "Newham" ...
$ local_authority_ons_district : chr [1:192286] "Wandsworth" "Lambeth" "Westminster" "Newham" ...
$ local_authority_highway : chr [1:192286] "Wandsworth" "Lambeth" "Westminster" "Newham" ...
$ first_road_class : chr [1:192286] "Unclassified" "A" "C" "A" ...
$ first_road_number : chr [1:192286] "first_road_class is C or Unclassified. These roads do not have official numbers so recorded as zero" "3036" "first_road_class is C or Unclassified. These roads do not have official numbers so recorded as zero" "11" ...
$ road_type : chr [1:192286] "Single carriageway" "Single carriageway" "Single carriageway" "Single carriageway" ...
$ speed_limit : chr [1:192286] "20" "20" "30" "30" ...
$ junction_detail : chr [1:192286] "Not at junction or within 20 metres" "Other junction" "T or staggered junction" "Not at junction or within 20 metres" ...
$ junction_control : chr [1:192286] "Data missing or out of range" "Auto traffic signal" "Authorised person" "Data missing or out of range" ...
$ second_road_class : chr [1:192286] "Not at junction or within 20 metres" "Unclassified" "Unclassified" "Not at junction or within 20 metres" ...
$ second_road_number : chr [1:192286] "Unknown" "first_road_class is C or Unclassified. These roads do not have official numbers so recorded as zero" "first_road_class is C or Unclassified. These roads do not have official numbers so recorded as zero" "Unknown" ...
$ pedestrian_crossing_human_control : chr [1:192286] "unknown (self reported)" "None within 50 metres" "None within 50 metres" "None within 50 metres" ...
$ pedestrian_crossing_physical_facilities : chr [1:192286] "unknown (self reported)" "Pelican, puffin, toucan or similar non-junction pedestrian light crossing" "No physical crossing facilities within 50 metres" "Pelican, puffin, toucan or similar non-junction pedestrian light crossing" ...
$ light_conditions : chr [1:192286] "Daylight" "Daylight" "Darkness - lights lit" "Darkness - lights lit" ...
$ weather_conditions : chr [1:192286] "Unknown" "Fine no high winds" "Fine no high winds" "Fine no high winds" ...
$ road_surface_conditions : chr [1:192286] "unknown (self reported)" "Dry" "Wet or damp" "Dry" ...
$ special_conditions_at_site : chr [1:192286] "None" "None" "None" "None" ...
$ carriageway_hazards : chr [1:192286] "None" "None" "None" "None" ...
$ urban_or_rural_area : chr [1:192286] "Urban" "Urban" "Urban" "Urban" ...
$ did_police_officer_attend_scene_of_accident: chr [1:192286] "No - accident was reported using a self completion form (self rep only)" "Yes" "Yes" "Yes" ...
$ trunk_road_flag : chr [1:192286] "Non-trunk" "Non-trunk" "Non-trunk" "Non-trunk" ...
$ lsoa_of_accident_location : chr [1:192286] "E01004576" "E01003034" "E01004726" "E01003617" ...
$ enhanced_severity_collision : num [1:192286] -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
$ datetime : POSIXct[1:192286], format: "2020-02-04 09:00:00" "2020-04-27 13:55:00" ...
- attr(*, "spec")=
.. cols(
.. accident_index = col_character(),
.. accident_year = col_integer(),
.. accident_reference = col_character(),
.. location_easting_osgr = col_integer(),
.. location_northing_osgr = col_integer(),
.. longitude = col_integer(),
.. latitude = col_integer(),
.. police_force = col_character(),
.. accident_severity = col_character(),
.. number_of_vehicles = col_character(),
.. number_of_casualties = col_character(),
.. date = col_character(),
.. day_of_week = col_character(),
.. time = col_character(),
.. local_authority_district = col_character(),
.. local_authority_ons_district = col_character(),
.. local_authority_highway = col_character(),
.. first_road_class = col_character(),
.. first_road_number = col_character(),
.. road_type = col_character(),
.. speed_limit = col_character(),
.. junction_detail = col_character(),
.. junction_control = col_character(),
.. second_road_class = col_character(),
.. second_road_number = col_character(),
.. pedestrian_crossing_human_control = col_character(),
.. pedestrian_crossing_physical_facilities = col_character(),
.. light_conditions = col_character(),
.. weather_conditions = col_character(),
.. road_surface_conditions = col_character(),
.. special_conditions_at_site = col_character(),
.. carriageway_hazards = col_character(),
.. urban_or_rural_area = col_character(),
.. did_police_officer_attend_scene_of_accident = col_character(),
.. trunk_road_flag = col_character(),
.. lsoa_of_accident_location = col_character(),
.. enhanced_severity_collision = col_double()
.. )
- attr(*, "problems")=<externalptr>
# aggregate this by day to show
# how crash numbers varied over the year
ac_by_year = ac |>
group_by (date) |>
summarise (
n_crashes = n ()
)
ac_by_year |>
mutate (
` N. crashes per year ` = n_crashes,
` Week average ` = zoo:: rollmean (n_crashes, 7 , na.pad = TRUE ),
Date = date,
) |>
ggplot (aes (x = Date, y = ` N. crashes per year ` )) +
geom_point (alpha = 0.1 ) +
ylim (c (0 , NA )) +
# geom_smooth() +
# weekly rolling average
geom_line (aes (Date, ` Week average ` ), colour = "red" ) +
theme_minimal ()