This question already has an answer here:
- ggplot2: Drop unused factors in a faceted bar plot but not have differing bar widths between facets 3 answers
I am generating faceted barchart with ggplot. I have the problem that the MWE below generates the graph at the bottom. I would like it to generate bars that have the same widths in both facets. How would I go about this?
library(ggplot2)
df = data.frame(x = as.factor(c(1, 2, 3, 1, 2)),
y = c(2, 3, 4, 5, 6),
g = c(1, 1, 1, 2, 2));
ggplot(df, aes(x = 1, y = y, fill = x)) +
geom_bar(stat = "identity",
position = "dodge") +
facet_wrap(~ g);