I have a dataframe containing values for three variables at three different dates:
df <- data.frame(date = as.Date(c(rep('2021-01-01',6),rep('2021-05-04',6),rep('2015-04-04',6))),
variable = rep(c('apple','bananna','carrot'),6),
value = rnorm(18,5,2))
I'd like to make a boxplot with fill relating to variable, date on the x axis and value on the y axis:
ggplot(df,aes(x=as.factor(date),y=value,fill=variable))+geom_boxplot()
This fills based on variable, but it doesn't scale date according to the actual differences in time:

If I set group=date, it gets scaled properly, but fill=variable stops working:
ggplot(df,aes(x=date,y=value,group=date,fill=variable))+geom_boxplot()
How do I get the date to scale properly and also fill based on variable name?



