stacked bar plot with ggplot

前端 未结 2 806
渐次进展
渐次进展 2021-01-28 04:26

I\'m trying to make a stacked bar plot with the following dataframe:

 totalleft
        1S 2S 3S 4S 12S 25S      tests
A-000   5  0 10 10   0  NA       A-000
A-0         


        
2条回答
  •  不要未来只要你来
    2021-01-28 05:10

    This seems like what you wanted??

    library(reshape2)
    library(ggplot2)
    
    gg <- melt(totalleft,id="tests")
    ggplot(gg) +
      geom_bar(aes(x=tests, y=value, fill=variable), stat="identity")+
      theme(axis.text.x=element_text(angle=-90, vjust=.2, hjust=0))
    

    melt(...) converts your data frame from "wide" format (groups in different columns) to "long" format (all the values in one column (called value), and groups distinguished by a separate column (called variable).

提交回复
热议问题