Last active
February 23, 2016 16:06
-
-
Save cavedave/f1db0efb2f5478bf9ee1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#read in SF crime data is at https://www.kaggle.com/c/sf-crime/data | |
mydata = read.csv("train.csv") | |
library(dplyr) | |
#break up times | |
mydata$Year <- year(mydata$Dates) | |
mydata$Month <- month(mydata$Dates) | |
mydata$Hour <- hour(mydata$Dates) | |
mydata$Weekend <- mydata$DayOfWeek %in% c("Saturday", "Sunday") | |
mydata$TimeOfDay <- cut(mydata$Hour, | |
c(0, 6, 12, 18, 24), | |
labels = c("Overnight", "Morning", "Afternoon", "Evening"), | |
right = FALSE) | |
#get one popular crime type | |
larcen <- filter(mydata, Category == "LARCENY/THEFT") | |
#make a graph of it | |
ggplot(larcen, aes(x = Hour, fill = DayOfWeek)) + | |
geom_histogram(breaks = seq(0, 24), width = 1, colour = "blue") + | |
coord_polar(start = 0) + | |
theme_minimal() + | |
scale_fill_brewer() + ylab("Thefts Number")+ | |
scale_x_continuous("", limits = c(0, 24), breaks = seq(0, 24), | |
labels = seq(0, 24))+ | |
ggtitle("SF Thefts per Hour and Day") | |
ggsave("theftClock.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment