Issue with geom_text when using position_dodge

前端 未结 1 376
情书的邮戳
情书的邮戳 2020-11-27 07:07

I saw this answer but couldn\'t replicate it.

I get my data like this:

df = data.frame(x = rep(sample(letters, 4), 2), 
                y = round(run         


        
相关标签:
1条回答
  • 2020-11-27 07:35

    Just one minor change solves the issue. You need to specify group=x inside your geom_text(aes(...)) call.

    ggplot(df) + 
    geom_bar(aes(z, y, fill=x), position=position_dodge(width=1), stat="identity") + 
    geom_text(aes(z,y,label=perc, group=x), position=position_dodge(width=1), size=4)
    

    enter image description here

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