How to create a "nested" histogram?

The last image in this blog post .

I tried to find a "nested histogram" and a "hierarchical histogram", but that might not be the word for it.

+6
source share
3 answers

Use ggplot and create separate layers:

 library(ggplot2) set.seed(1) stupid <- data.frame( group= LETTERS[1:5], men = sample(1:10, 5), women = sample(1:10, 5) ) # Melt the data and calculate totals mstupid <- melt(stupid, id.vars="group") stupidTotal <- ddply(mstupid, .(group), summarize, value=sum(value)) ggplot() + geom_bar(data=stupidTotal, aes(x=group, y=value), fill="grey50") + geom_bar(data=mstupid, aes(x=group, y=value, fill=variable), stat="identity", position="dodge") + theme_bw() 

enter image description here

+9
source

Find "barNest" in the plotrix package

+1
source

Use this:

 ggplot() + geom_bar(data=stupidTotal, aes(x=group, y=value, fill="grey50"), stat="identity") + geom_bar(data=mstupid, aes(x=group, y=value, fill=variable), stat="identity", position="dodge") + theme_bw() 
0
source

Source: https://habr.com/ru/post/900999/


All Articles