######################################
#  Premise Breakdown
######################################
per_premises <- master %>%
  group_by(Premises) %>%
  summarise(total=n())
ggplot(data=per_premises, mapping= aes(x=reorder(Premises,total), y=total) ) +
  geom_bar(stat="identity") +
  coord_flip() +
  labs(title="Total crime reports in the Heights 2010-2017", y="Total incidents",x="Premise")

######################################
#  Stacked bar of incident type vs. premise
######################################
per_offense_premise <- master %>% 
  group_by(Premises, Offense_Type) %>% 
  summarize(offenses=n())
a = per_offense_premise %>%
  group_by(Premises) %>%
  summarise(ordering=sum(offenses))
per_offense_premise <-  
  left_join(per_offense_premise,a,by="Premises")
per_offense_premise$Premises <-
  reorder(per_offense_premise$Premises, per_offense_premise$ordering)
  
ggplot(data=per_offense_premise, mapping= aes(x=Premises, y=offenses) ) +
  geom_col(aes(fill=Offense_Type))+
  coord_flip() +
  labs(title="Total crime reports in the Heights 2010-2017", y="Total incidents by Type",x="Premise")

######################################
#  Stacked bar of incident type vs. premise
######################################
residential <- master %>%
  filter(Premises=="Residence")
per_month = residential %>% 
  mutate(mon = as.numeric(format(Date, "%m")), yr = as.numeric(format(Date, "%Y"))) %>%
  mutate(YrMon=yr+mon/12) %>%
  filter(YrMon>2010) %>%
  group_by(YrMon, Offense_Type) %>%
  summarize(total=n())
ggplot(data=per_month, mapping=aes(x=YrMon, y=total, color=Offense_Type)) +
  geom_point() +
  geom_smooth(method="lm") +
  labs(title="Total incidents in the Heights ", y="Total incidents per month", x="Averaged Monthly") +
  labs(subtitle="With linear regression")

######################################
#  Residential thefts by month
######################################
residential_month <- residential %>%
  filter(as.numeric(format(Date, "%Y"))<2017) %>%
  mutate(Month = format(Date, "%m"), mon = as.integer(format(Date,"%m"))) %>%
  group_by(mon, Month, Offense_Type) %>%
  summarize(total=n())
ggplot(data=residential_month, mapping=aes(x=Month, y=total, color=Offense_Type)) +
  geom_point() +
  geom_line(aes(x=mon, y=total)) +
  labs(title="Residential incidents in the Heights ", y="Incidents", x="Month")

######################################
#  Residential thefts in Nove & Dec
######################################
residential_NovDec <- residential %>%
  mutate(Month = format(Date, "%m"), Yr = as.integer(format(Date,"%Y"))) %>%
  filter((Month=="11") | (Month=="12")) %>%
  group_by(Yr, Offense_Type) %>%
  summarize(total=n())
ggplot(data=residential_NovDec, mapping=aes(x=Yr, y=total, color=Offense_Type)) +
  geom_point() +
  geom_smooth(method="lm", se=FALSE) +
  labs(title="November & December Residential Thefts", y="Thefts", x="Year")

######################################
#  Hour of day
######################################
master %>%
  group_by(Hour, Offense_Type) %>%
  summarize(total=n()) %>%
  ggplot(., aes(x=Hour, y=total, color=Offense_Type)) +
  geom_point() +
  geom_smooth() +
  labs(title="Incidents in the Heights by Hour of Day", x="Hour", y="Number of Incidents")