How to overlay two geom_bar?

后端 未结 1 1550
刺人心
刺人心 2020-12-03 02:05

I\'m trying to overlay 2 the bars from geom_bar derived from 2 separate data.frames.

dEQ
   lab perc
1  lmP 55.9
2  lmN 21.8
3   Nt  0.6
4 expG          


        
相关标签:
1条回答
  • 2020-12-03 02:30

    here is an example:

    p <- ggplot(NULL, aes(lab, perc)) + 
      geom_bar(aes(fill = "dEQ"), data = dEQ, alpha = 0.5) +
      geom_bar(aes(fill = "LMD"), data = LMD, alpha = 0.5)
    p
    

    enter image description here

    but I recommend to rbind them and plot it by dodging:

    dEQ$name <- "dEQ"
    LMD$name <- "LMD"
    d <- rbind(dEQ, LMD)
    p <- ggplot(d, aes(lab, perc, fill = name)) + geom_bar(position = "dodge")
    

    enter image description here

    0 讨论(0)
提交回复
热议问题