Hi people!
Finally I got some code plotting dates on x with a 1 till 12 scale.
Sadly the labels don't appear on the x-axis.
Can you please tell me how to force the labels to the x-scale?
The example dates start only on the first of each month. Real data can be any day within the months.
Smart date solutions are also very welcome. But main target is maintaining the 12 month scale.
Thank you.
library(tidyverse)
date <- c("03/01/2022","02/01/2022","01/01/2022","02/01/2022","01/01/2022",
"07/01/2022","05/01/2022","07/01/2022","06/01/2022","03/01/2022",
"02/01/2022","01/01/2022","07/01/2022","02/01/2022","01/01/2022",
"05/01/2022","06/01/2022","06/01/2022","05/01/2022","02/01/2022",
"01/01/2022","02/01/2022","02/01/2022","01/01/2022","05/01/2022",
"06/01/2022","04/01/2022","03/01/2022","02/01/2022","01/01/2022",
"02/01/2022","02/01/2022","05/01/2022","05/01/2022","06/01/2022",
"05/01/2022","03/01/2022","02/01/2022","01/01/2022","02/01/2022",
"01/01/2022","07/01/2022","05/01/2022","07/01/2022","06/01/2022",
"03/01/2022","02/01/2022","01/01/2022","07/01/2022","02/01/2022",
"01/01/2022","05/01/2022","06/01/2022","06/01/2022","05/01/2022",
"02/01/2022","01/01/2022","02/01/2022","02/01/2022","01/01/2022",
"05/01/2022","06/01/2022","04/01/2022","03/01/2022","02/01/2022",
"01/01/2022","02/01/2022","02/01/2022","05/01/2022","05/01/2022",
"06/01/2022","05/01/2022","05/01/2022","06/01/2022","04/01/2022",
"03/01/2022","02/01/2022","01/01/2022","02/01/2022","02/01/2022",
"05/01/2022","05/01/2022","06/01/2022","04/01/2022","03/01/2022",
"02/01/2022","01/01/2022","02/01/2022","02/01/2022","05/01/2022",
"05/01/2022","06/01/2022","04/01/2022","03/01/2022","02/01/2022",
"01/01/2022","02/01/2022","02/01/2022","05/01/2022","05/01/2022",
"06/01/2022")
amount <- c(1,1,0,1,1,1,1,0,8,1,1,1,1,1,1,1,2,1,1,1,8,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,9,1,1,1,1,1,1,1,1,
1,1,1,6,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,4,1,1,1,1,1,1,1,1,1,
1,1,1,1,1)
product <- c("cycle","ball","bat","tricycle","cycle","bat","ball","cycle",
"ball","cycle","ball","bat","tricycle","cycle","bat","ball",
"cycle","ball","cycle","ball","bat","tricycle","cycle","bat",
"ball","cycle","ball","cycle","ball","bat","tricycle","cycle",
"bat","ball","cycle","ball","ball","cycle","ball","bat",
"tricycle","cycle","bat","ball","cycle","ball","cycle","ball",
"bat","tricycle","cycle","bat","ball","cycle","ball","cycle",
"ball","bat","tricycle","cycle","bat","ball","cycle","ball",
"cycle","ball","bat","tricycle","cycle","bat","ball","cycle",
"ball","bat","ball","cycle","ball","cycle","ball","bat",
"tricycle","cycle","bat","ball","cycle","ball","cycle","ball",
"bat","tricycle","cycle","bat","ball","cycle","ball","cycle",
"ball","bat","tricycle","cycle","bat")
data <- data.frame(date, amount, product)
View(data)
data <-
aggregate(amount ~ date + product, data = data, FUN = sum, na.rm = TRUE)
ggplot(data,aes(x=date, y=amount, group=product))+
geom_line(aes(color=product)) +
scale_x_discrete(breaks = c(1,2,3,4,5,6,7,8,9,10,11,12),
labels= c("1","2","3","4","5","6","7","8","9","10","11","12"),
limits=c("01/01/2022","02/01/2022","03/01/2022","04/01/2022","05/01/2022",
"06/01/2022","07/01/2022","08/01/2022","09/01/2022","10/01/2022",
"11/01/2022","12/01/2022"))