开发者

Variable width bars in ggplot2 barplot in R

开发者 https://www.devze.com 2023-03-04 16:30 出处:网络
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

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()  


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")

Variable width bars in ggplot2 barplot in R

0

精彩评论

暂无评论...
验证码 换一张
取 消