Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #################################################
- ########ANALYSIS OF TOTAL DEATHS BY TIME#########
- #################################################
- by_borough$TIME = sapply(by_borough$TIME, function(x) paste0(x, ":00"))
- by_borough$TIME = times(by_borough$TIME)
- Night_Time_People_Deaths <- by_borough %>%
- filter(TIME > as.numeric(times('00:00:00')) & TIME < as.numeric(times('05:00:00'))) %>%
- summarise(Total_People_Killed_Night = sum(NUMBER.OF.PERSONS.KILLED))
- Morning_Time_People_Deaths <- by_borough %>%
- filter(TIME < as.numeric(times('12:00:00')) & TIME >= as.numeric(times('05:00:00'))) %>%
- summarise(Total_People_Killed_Morning = sum(NUMBER.OF.PERSONS.KILLED))
- Midday_People_Deaths <- by_borough %>%
- filter(TIME >= as.numeric(times('12:00:00')) & TIME < as.numeric(times('17:00:00'))) %>%
- summarise(Total_People_Killed_Midday = sum(NUMBER.OF.PERSONS.KILLED))
- Evening_People_Deaths <- by_borough %>%
- filter(TIME >= as.numeric(times('17:00:00'))) %>%
- summarise(Total_People_Killed_Evening = sum(NUMBER.OF.PERSONS.KILLED))
- Time_List = list(Morning_Time_People_Deaths, Midday_People_Deaths, Evening_People_Deaths, Night_Time_People_Deaths)
- Total_Death_Compared_by_Time = Reduce(function(x,y) merge(x,y, all = TRUE), Time_List)
- Total_Death_Compared_by_Time = mutate(Total_Death_Compared_by_Time, Total_Persons_Killed = apply(Total_Death_Compared_by_Time[,3:6], 1, sum))
- Total_Death_by_TimeofDay = ggplot(Total_Death_Compared_by_Time, aes(Year, colour = Time_Ranges)) +
- ylab("Number of Deaths\n") +
- xlab("\nYear") +
- geom_line(aes(y = Total_People_Killed_Morning, colour = "Morning- (05:00 - 11:59)")) +
- geom_line(aes(y = Total_People_Killed_Midday, colour = "Midday- (12:00 - 16:59)")) +
- geom_line(aes(y = Total_People_Killed_Evening, colour = "Evening- (17:00 - 23:59)")) +
- geom_line(aes(y = Total_People_Killed_Night, colour = "Night - (00:00 - 04:59)")) +
- facet_grid(.~BOROUGH) +
- theme_economist() +
- theme(legend.text=element_text(size=7)) +
- theme(axis.text.x = element_text(size = 7 , angle = 90, hjust = 0)) +
- theme(axis.text.y = element_text(size = 7 , angle = 0, hjust = 0)) +
- ggtitle('Total People Killed in Collisions - Time of Day')
- Total_Death_by_TimeofDay
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement