I would like to draw plot with the same width of the bars. Here's my minimal example code:
data <- data.frame(A = letters[1:17],
B = sample(1:500, 17),
C = c(rep(1, 5), rep(2, 6), rep(c(3,4,5), each = 2)))
ggplot(data,
aes(x = C, y = B, label = A,
fill = A)) +
geom_bar(stat = "identity", position = "dodge") +
geom_text(position = position_dodge(width = 0.9), angle = 90)
The result is shown in the picture above:
The width of the bars is dependent on numbers of observation in group given in variable C
. I want to have each bar to have the same width.
The facet_grid(~C)
works (bars are the same width) it's not what I mean:
ggplot(data,
aes(x = C, y = B, label = A,
fill = A)) +
geom_bar(stat = "identity", position = "dodge") +
geom_text(position = position_dodge(width = 0.9), angle = 90) +
facet_grid(~C)
What I want is to have plot like in the first picture but with bars's width independent on number of observation in each level from column C
. How can I do it?
[EDIT] geom_bar(width)
changes width of the bars'group but still bars in fifth group are wider than in the first group, so it's not the answer to my question.