27

I'm trying to produce a barplot with bar widths determined by an integer variable (sample size). Adding "width = variableName" doesn't seem to work. Is there an established way of doing this? Here's some dummy data and code. I want the bar widths to be a function of variable d in this example.

dat <- data.frame(a=c("A", "B", "C"), b=c(0.71, 0.94, 0.85), d=c(32, 99, 18))

ggplot(dat, aes(x=a, y=b, fill=a)) +  
geom_bar(colour="black", size=.3) + 
theme_bw()  
Steve
  • 5,727
  • 10
  • 32
  • 30

1 Answers1

39

How about using width= after rescaling your d vector, say by a constant amount?

ggplot(dat, aes(x=a, y=b, width=d/100)) + 
  geom_bar(aes(fill=a), stat="identity", position="identity")

enter image description here

chl
  • 27,771
  • 5
  • 51
  • 71