Problem: Why does ggplot2 removes 2 rows when plotting the below data? In particular, it removes the first and the last row although the specified x-axis date range (2020-01-01 until 2020-01-03) should contain all values?
Warning Message:
Warning message:
Removed 2 rows containing missing values
(geom_bar).
Code:
library(ggplot2)
library(scales)
dt_object <- data.table(
loc = c(rep("A", 3), rep("B", 3)),
dt = rep(seq.Date(as.Date("2020-01-01"), as.Date("2020-01-03"), length.out = 3), 2),
vals = c(500, 200, 100, 1000, 400, 300)
)
ggplot(dt_object, aes(x = dt, y = vals, fill = loc))+
geom_bar(position = "dodge", stat = "identity")+
scale_x_date(date_breaks = "1 month",
labels=date_format("%b %Y"),
limits = as.Date(c("2020-01-01", "2020-01-03")))
Edit: I know that I can specify the x-axis wider (e.g. 2019-12-31, 2020-01-04) but I would like to have the exact specified date range as in my question as input to ggplot