i have data looks this:
subcategory title value sub1 name1 2 sub1 name2 5 sub2 name3 4 sub2 name4 1 sub3 name5 2 sub3 name6 7 sub4 name1 7 sub4 name2 5 sub5 name3 4 sub5 name4 3 sub6 name5 9 sub6 name6 1
adding title row field , sum(value) size shelf, horizontal bar chart length of bar equivalent sum of values given title. example, bar labeled name1 , 9 units long, labeled name2 , 10 units long, etc. want color bar such contribution of given subcategory bar length painted on bar. name1 bar have blue bar 2 units long stacked on red bar 7 units long. name 2 bar have blue bar 5 units long stacked on orange bar 5 units long.
however, when add subcategory color shelf, scale changes length of bar equal highest value of subcategory , other values not stacked, superimposed. instead of getting 2 unit blue bar stacked on 7 unit red bar total length of 9, bar of 7 total units 2 units painted blue.
this changes interpretation "what's category highest values (and how subcategories contribute this)?" "what's category highest subcategory?" because name1 bar 7 units whereas name2 bar 5 units long , can't see other color.
please let me know if there's way in tableau, or if you're ggplot2 wizard, i'll happily take r code same.
check this, not sure if coloring right:
library("ggplot2") p <- ggplot(data=dat, aes(x=title, y=value, fill=subcategory)) + geom_bar(position="stack", stat="identity") + coord_flip() print(p)
Comments
Post a Comment