Out of order text labels on stack bar plot (ggplot)

后端 未结 1 1690
后悔当初
后悔当初 2020-12-11 10:21

I\'m trying to make a stacked bar chart with text labels, this some example data / code:

library(reshape2)

ConstitutiveHet <- c(7,13)
Enhancer <- c(12         


        
相关标签:
1条回答
  • 2020-12-11 10:59
    ggplot(meanCombM,aes(group,value,label=value)) +
         geom_col(aes(fill=variable))+
         geom_text(aes(group=variable),position = position_stack(vjust = 0.5))+
         coord_flip()
    

    Hadley answered a question similar to my own in this issue in ggplot2's git repository: https://github.com/tidyverse/ggplot2/issues/1972

    Apparently the default grouping behaviour (see: http://ggplot2.tidyverse.org/reference/aes_group_order.html) does not partition the data correctly here without specifying a group aesthetic, which should map to the same value as fill in geom_col in this example.

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