That lubridate command worked! Thanks a lot, I just changed the Month and Date column in their respective original datasets to a "date" class.
The reason why there isn't enough data is because that was just a sample of df4, since it has over 26k rows.
A person in another forum suggested not to merge the two datasets in the first place, so
I tried using ggplot with the two datasets separately without merging them, and it works!!! I just need to :
1) figure out how to scale the second Y axis properly for the Unemployment Rate
2) remove the "England" plot, maybe using filter() within geom_line(data =)
I tried scaling the Y axis by using a set of breaks from 0 to 6 but it only grouped them at the bottom of the Y axis on the right, following the left side scale.
Here's the output I have now, and below is the code I used to achieve it
crime_count<-crimedata %>%
count(Region, Date, Crime, name = 'Crime_occurrencies') %>% #to count categorical variables
ggplot(mapping=aes(Date)) +
geom_line(aes(y = Crime_occurrencies, colour = Crime),
data = crime_count) +
geom_line(mapping = aes(Date, Unemployment.rate, linetype = "Unemployment Rate"),
col = "black", data = Unemp_long,) +
facet_wrap(~Region,
scales = "free_y") +
scale_x_date(breaks = seq(as.Date("2019-01-01"), as.Date("2020-10-01"), by="1 month"),
date_labels = '%m %Y') +
scale_y_continuous(sec.axis = sec_axis(~ (.- 249) * 0.00853131 + 2.990426)) +
theme(axis.text.x=element_text(angle =- 90, vjust = 0.5))```