Adding labels to ggplot bar chart

后端 未结 2 1375
挽巷
挽巷 2020-11-29 03:47

I would like to do a bar plot outlined in black with percentages inside the bars. Is this possible from qplot? I get the percentages to appear but they don\'t align with th

2条回答
  •  一整个雨季
    2020-11-29 04:33

    Here you go:

    library(scales)
    ggplot(x, aes(x = filename, fill = variable)) +
      geom_bar(stat="identity", ymin=0, aes(y=value, ymax=value), position="dodge") +
      geom_text(aes(x=filename, y=value, ymax=value, label=value, 
                    hjust=ifelse(sign(value)>0, 1, 0)), 
                position = position_dodge(width=1)) +
      scale_y_continuous(labels = percent_format()) +
      coord_flip()
    

    enter image description here

提交回复
热议问题