I'm new to using R and ggplot2, and I cannot figure out how to fix the issue with the graph I am trying to create.
Here is what the graph looks like at the moment. I have dates on the x-axis, but for some reason they don't work with the year, but only order by the month and day.
Here is a screenshot of the data I am working with:
As you can see, the order looks correct here.
I produced a re-creatable sample where the same issue occurs
Week <- c("1/6/2019", "1/26/2020", "6/7/2020")
Coronavirus <- c(0, 16, 67)
Grubhub <- c(65, 23, 59)
UberEats <- c(52, 80, 68)
Doordash <- c(27, 35, 50)
my.data <- data.frame(Week, Coronavirus, Grubhub, UberEats, Doordash)
my.data
test.output <- ggplot(data = my.data, aes(x = Week, group = 1)) +
geom_line(aes(y = Coronavirus), color = "red") +
geom_line(aes(y = Grubhub), color = "darkgreen") +
geom_line(aes(y = UberEats), color = "blue") +
geom_line(aes(y = Doordash), color = "purple") +
theme(axis.text.x = element_text(angle = 90)) +
labs(title = "Weekly Google Search Term Interest by Category", y = "Search Term Interest", x = "Week [2020]")
test.output
The order of the dates on the x-axis are incorrect here as well.
Any suggestions on how I can fix the issue?