Advertisement
CastelShal

Dont go to chicago

Jan 10th, 2025 (edited)
1,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.78 KB | None | 0 0
  1. library(mongolite)
  2. library(lubridate)
  3. library(ggplot2)
  4.  
  5. data = mongo(collection="crimes", db="test")
  6. domestic = data$find('{"Domestic": true}')
  7.  
  8. hours = hour(parse_date_time(domestic$Date, c("mdy-HMS %p", "mdy-HM")))
  9. days = weekdays(parse_date_time(domestic$Date, c("mdy-HMS %p", "mdy-HM")))
  10.  
  11. hour(parse_date_time("03/18/2015 11:30:00 AM", c("mdy-HMS", "mdy-HM")))
  12.  
  13. plotData = as.data.frame(table(days, hours))
  14. dayType = ifelse(days %in% c("Saturday", "Sunday"), "Weekend", "Weekday")
  15.  
  16. dayData = as.data.frame(table(hours, dayType))
  17.  
  18. #ggplot(plotData, aes(x = hours, y = Freq, group=days, color=days)) +
  19. #  geom_line() + ggtitle("Don't go to Chicago")
  20.  
  21. ggplot(dayData, aes(x = hours, y = Freq, group=dayType, color=dayType)) +
  22.   geom_line() + ggtitle("Don't go to Chicago")
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement