Barchart of count of true/false values by group (dodged graphs)

后端 未结 1 1242
一生所求
一生所求 2020-12-21 06:31

I am rather new in R and ggplot. And I am not sure if what I want is doable.

Here is (a portion of) my data:

> mdf
   Batch     A     B     C              


        
相关标签:
1条回答
  • 2020-12-21 06:57

    Yes it's possible, you just need to reshape your data first, then you can use position = "dodge" to draw a bar for each key. With tidyr:

    library(tidyr)
    library(dplyr)
    library(ggplot2)
    
    mdf %>% gather(key, value, -Batch) %>%
      ggplot(.,(aes(Batch, as.numeric(value), fill = key))) +
      stat_summary(fun.y = sum, geom = "bar", position = "dodge")
    
    0 讨论(0)
提交回复
热议问题