I am working with the R programming language.
I have a data file (called "my_data") with a date variable ("my_date") that is in a DAY-MONTH-YEAR format, and the dates are in "factor" format. The dates look like this : 05-OCT-21
I am trying to make a time series plot of this data, in which I count the total number of observations in each month over a set of years, grouped by groupings in another variable ("group_var"). I tried to do this using the "dplyr" library:
library(dplyr)
library(ggplot2)
new <- my_data %>%
mutate(date = as.Date(my_date)) %>%
group_by(group_var, month = format(date, "%Y-%m")) %>%
summarise( count = n())
plot <- ggplot(new) + geom_line(aes(x = month, y = count, color = group_var, group = group_var)) + scale_colour_manual(values = c("red", "green", "blue")) + theme(axis.text.x = element_text(angle = 90)) + ggtitle("my title")
Can someone please show me what I am doing wrong?