Adding percentage labels on pie chart in R

前端 未结 5 1378
渐次进展
渐次进展 2020-12-03 19:23

My data frame looks like

df
   Group   value
1 Positive    52
2 Negative   239
3 Neutral     9

I would like to make a pie chart of the dat

5条回答
  •  没有蜡笔的小新
    2020-12-03 20:15

    How about:

    vals <- c(239, 52, 9)
    val_names <- sprintf("%s (%s)", c("Negative", "Positive", "Neutral"), scales::percent(round(vals/sum(vals), 2)))
    names(vals) <- val_names
    
    waffle::waffle(vals) +
      ggthemes::scale_fill_tableau(name=NULL)
    

    instead?

    It's "fresher" than a pie chart and you aren't really gaining anything with the level of precision you have/want on those pie labels now.

提交回复
热议问题