Annotation above bars:

后端 未结 2 680
长发绾君心
长发绾君心 2020-12-01 18:42

dodged bar plot in ggplot again has me stumped. I asked about annotating text above bars on here a few weeks back (LINK) and got a terrific response to use + stat_bin

2条回答
  •  借酒劲吻你
    2020-12-01 19:35

    I was having trouble getting the position dodges to line up, so I ended up creating a position_dodge object (is that the right terminology?), saving it to a variable, and then using that as the position for both geoms. Somewhat infuriatingly, they still seem to be a little off centre.

    dodgewidth <- position_dodge(width=0.9)
    ggplot(dat,aes(x = type,y = count, fill = group)) + 
      geom_bar(colour = "black", position = dodgewidth ,stat = "identity") +
      stat_bin(geom="text", position= dodgewidth, aes(x=type, label=count), vjust=-1)
    

    enter image description here

提交回复
热议问题