R ggplot barplot; Fill based on two separate variables

前端 未结 3 1891
挽巷
挽巷 2020-12-13 20:31

A picture says more than a thousand words. As you can see, my fill is based on the variable variable.

Within each bar there is however mul

3条回答
  •  盖世英雄少女心
    2020-12-13 20:40

    You might need to separate your Method and variable factors. Here are two ways to do that:

    Use facet_wrap():

        ggplot(short.m, aes(x=variable, y=value/100, fill=Complexity)) + 
        facet_wrap(~ Method) + geom_bar(position="stack", colour="black") +
        scale_alpha_manual(values=c(0.1, 0.5, 1)) + coord_flip()
    

    Use both on the x-axis:

        ggplot(short.m, aes(x=Method:variable, y=value/100, group=Method, fill=variable, alpha=Complexity,)) + 
        geom_bar(stat="identity", position="stack", colour="black") +
        scale_alpha_manual(values=c(0.1, 0.5, 1)) + coord_flip()
    

提交回复
热议问题