Adding labels to ggplot bar chart

后端 未结 2 1379
挽巷
挽巷 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:31

    This would be a good opportunity for you to start moving away from using qplot, in favor of ggplot. This will be much easier in the long run, trust me.

    Here's a start:

    library(scales)
    ggplot(data = x,aes(x = factor(filename),y = value)) + 
        geom_bar(aes(fill = factor(variable)),colour = "black",position = 'dodge') + 
        coord_flip() + 
        scale_fill_manual(name = '',
                          labels = c('low',
                                     'Hi',
                                     "Tot"),
                          values = c('#40E0D0',
                                     '#FF6347',
                                     "#C7C7C7")) + 
        scale_y_continuous(labels = percent_format())
    

    For philosophical reasons, I will leave the annotation piece to you...

提交回复
热议问题