Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. #################################################
  2. ########ANALYSIS OF TOTAL DEATHS BY TIME#########
  3. #################################################
  4.  
  5. by_borough$TIME = sapply(by_borough$TIME, function(x) paste0(x, ":00"))
  6. by_borough$TIME = times(by_borough$TIME)
  7.  
  8. Night_Time_People_Deaths <- by_borough %>%
  9. filter(TIME > as.numeric(times('00:00:00')) & TIME < as.numeric(times('05:00:00'))) %>%
  10. summarise(Total_People_Killed_Night = sum(NUMBER.OF.PERSONS.KILLED))
  11.  
  12. Morning_Time_People_Deaths <- by_borough %>%
  13. filter(TIME < as.numeric(times('12:00:00')) & TIME >= as.numeric(times('05:00:00'))) %>%
  14. summarise(Total_People_Killed_Morning = sum(NUMBER.OF.PERSONS.KILLED))
  15.  
  16. Midday_People_Deaths <- by_borough %>%
  17. filter(TIME >= as.numeric(times('12:00:00')) & TIME < as.numeric(times('17:00:00'))) %>%
  18. summarise(Total_People_Killed_Midday = sum(NUMBER.OF.PERSONS.KILLED))
  19.  
  20. Evening_People_Deaths <- by_borough %>%
  21. filter(TIME >= as.numeric(times('17:00:00'))) %>%
  22. summarise(Total_People_Killed_Evening = sum(NUMBER.OF.PERSONS.KILLED))
  23.  
  24. Time_List = list(Morning_Time_People_Deaths, Midday_People_Deaths, Evening_People_Deaths, Night_Time_People_Deaths)
  25. Total_Death_Compared_by_Time = Reduce(function(x,y) merge(x,y, all = TRUE), Time_List)
  26. Total_Death_Compared_by_Time = mutate(Total_Death_Compared_by_Time, Total_Persons_Killed = apply(Total_Death_Compared_by_Time[,3:6], 1, sum))
  27.  
  28.  
  29. Total_Death_by_TimeofDay = ggplot(Total_Death_Compared_by_Time, aes(Year, colour = Time_Ranges)) +
  30. ylab("Number of Deaths\n") +
  31. xlab("\nYear") +
  32. geom_line(aes(y = Total_People_Killed_Morning, colour = "Morning- (05:00 - 11:59)")) +
  33. geom_line(aes(y = Total_People_Killed_Midday, colour = "Midday- (12:00 - 16:59)")) +
  34. geom_line(aes(y = Total_People_Killed_Evening, colour = "Evening- (17:00 - 23:59)")) +
  35. geom_line(aes(y = Total_People_Killed_Night, colour = "Night - (00:00 - 04:59)")) +
  36. facet_grid(.~BOROUGH) +
  37. theme_economist() +
  38. theme(legend.text=element_text(size=7)) +
  39. theme(axis.text.x = element_text(size = 7 , angle = 90, hjust = 0)) +
  40. theme(axis.text.y = element_text(size = 7 , angle = 0, hjust = 0)) +
  41. ggtitle('Total People Killed in Collisions - Time of Day')
  42.  
  43.  
  44. Total_Death_by_TimeofDay
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement