ggplot2 - piechart - value labels in reverse order

前端 未结 1 622
轮回少年
轮回少年 2021-01-14 15:58

I am trying to match labels with my pie chart with ggplot2:

Code:

values=c(59,4,4,11,26)
labels=c(\"catA\", \"catB\",\"catC\",\"catD\",\"catE\")
pos          


        
1条回答
  •  梦毁少年i
    2021-01-14 16:42

    Starting in ggplot2 2.2.0, you can use position_stack with vjust = .5 to center labels in stacked bars charts (and so pie charts). You no longer need to calculate the position outside of ggplot2. See the NEWS for more details on these changes.

    ggplot(values, aes(x = "", y = val, fill = Type)) + 
        geom_bar(width = 1,stat="identity") + 
        geom_text(aes(label = val), size=3, position = position_stack(vjust = 0.5))  + 
        coord_polar(theta = "y")
    

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