Drawing bars with variable widths is a common request and I found many solutions here at SO, but they all seem to work only when the plot consists of individual bars while I have them in groups:
set.seed(1)
dat <- data.frame(group=c('foo', 'foo', 'foo', 'bar', 'xyz', 'xyz'),
indiv=c('foA', 'foB', 'foC', 'baD', 'xyE', 'xyF'),
val=sample(30:90, 6),
wid=sample(2:8, 6)
)
ggplot(dat, aes(x=group, y=val)) +
geom_bar(aes(fill=indiv), stat="identity", position="dodge") +
theme_bw() # btw this also doesn't work as expected but that's another question
Here is what I get:
And what I need is something like this:
(this picture is the result of my workaround shown in the answer below)