Hi everyone,
I'm not succeeding having the same column width for groups A and B in my plot.
OK, there's no year 2001 in group 'B'.
But I don't understand why the column width for this group are automatically increased.
How can I correct this ?
library(tidyverse)
df1 <- data.frame(
year = factor(2001:2004),
group = rep("A", 4),
value = c(50, 60, 100, 40)
)
df2 <- data.frame(
year = factor(2002:2004),
group = rep("B", 3),
value = c(90, NA, 150)
)
rbind(df1, df2) |>
ggplot(aes(x = group, y = value, fill = year)) +
geom_col(width = 0.8, position = "dodge2") +
scale_fill_grey()