A few years ago a question was asked why geom_bar has trouble with yearmon. The proposed solution doesn't work any longer with an updated version of ggplot.
Here is a minimal example with ggplot 3.3.0:
library(zoo)
library(data.table)
library(ggplot2)
# geom_col can handle yearmon when only Jannuary data are conained
dt_tmp <- data.table(time_period = as.yearmon(c(2019, 2019, 2020)),
count_cases = c(1:2, 10),
group = c("a", "b", "a"))
ggplot(dt_tmp, aes(x = time_period, y = count_cases, fill = group)) +
geom_col() +
scale_x_yearmon(breaks = sort(unique(dt_tmp$time_period)))
# however with anything esle than January geom_col has trouble
dt_tmp <- data.table(time_period = as.yearmon(c(2019, 2019, 2019 + 1/12)),
count_cases = c(1:2, 10),
group = c("a", "b", "a"))
ggplot(dt_tmp, aes(x = time_period, y = count_cases, fill = group)) +
geom_col() +
scale_x_yearmon(breaks = sort(unique(dt_tmp$time_period)))
# however geom_line and geom_point can
ggplot(dt_tmp, aes(x = time_period, y = count_cases, colour = group)) +
geom_line() +
geom_point()
And once we include any other month than January we end up with:
So what changed or what am I missing? Is this a bug?