What units are the 'width = ' in geom_bar(aes = ) and position_dodge(width = ) rendered in?

后端 未结 1 1998
别跟我提以往
别跟我提以往 2021-01-22 17:08

I want to layer something specifically on one of the dodged bars, how would I be able to do that?

In the below example, I want to layer something specifically on A3 in t

相关标签:
1条回答
  • 2021-01-22 18:05

    The width argument in position_dodge() is specifying the distance between the leftmost edge of the left bar and the rightmost edge of the right bar. With a dodge width of 0.8, the distance between your start point of x = 3 for your x3 category and the edge of either bar is 0.4 (+0.4 on the right and -0.4 on the left) Half of 0.4 (i.e. 0.2) will bring you to midpoint of the bar (again +0.2 on the right and -0.2 on the left). This is true irrespective of the bar width.

    Here's an example where I've drawn an H on the right bar in cat3. The y-units line up with those on the y-axis.

    ggplot(data,aes(y = x1, x = x2)) + 
        geom_bar(stat = 'identity',
                 aes(fill = x3, width = 0.5), 
                 position = position_dodge(width = 0.8))+
        geom_text(aes(x = 3.2, y = 25, label = "H"), size = 10)
    

    UpdatedImageWithLetterH

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