Hello Community,
Hope all is well. When I run this code below, I receive the following error:
Error: Invalid input: date_trans works with objects of class Date only
When running line by line, it seems that the scales_x_date is not working properly.
Any help would be amazing. I will keep pushing, hopefully I find a break fingers crossed
library(tidyverse)
library(leaflet)
library(ggrepel)
library(ggplot2)
library(scales)
data <- read_csv("SFPD_Incident_Reports_2003_May2018.csv")
fil_calls <- data %>%
filter(Category == "SUSPICIOUS OCC")
# mutating for annual year, and rounding time to nearest hour (24 hour clock, military time)
suspicious <- fil_calls %>%
mutate(Year = format(as.Date(Date, "%m/%d/%Y"), format = "%Y")) %>%
mutate(Date = format(as.Date(Date, "%m/%d/%Y"))) %>%
mutate(Hour = format(strptime(Time, "%H:%M:%S"), '%H')) %>%
select(Hour, Year,Date, DayOfWeek, Category, Descript, PdDistrict, X, Y, Location)
# Calls over time
df_calls_daily <- suspicious %>%
group_by(Date) %>%
summarise(count = n()) %>%
arrange(Date)
plot <- ggplot2::ggplot(data = df_calls_daily, aes(x = Date, y = count)) +
geom_line(color = "#F2CA27", size = 0.1) +
geom_smooth(color = "1A1A1A") +
scale_x_date(breaks = date_breaks("1 year"), labels = date_format("%Y")) +
labs(x = "Date of Call", y = "Number of Calls", title = "Daily Calls in San Francisco from 2003 - 2018")
print(plot)