ggplot2-piechart-按相反顺序排列的值标签

ggplot2-piechart-按相反顺序排列的值标签,r,ggplot2,R,Ggplot2,我正在尝试将标签与带有ggplot2的饼图相匹配: 代码: 值=c(59,4,4,11,26) 标签=c(“catA”、“catB”、“catC”、“catD”、“catE”) pos=总和(值)-值/2 图形从ggplot2 2.2.0开始,您可以使用position_stack和vjust=.5将标签置于堆叠条形图(以及饼图)的中心。您不再需要计算ggplot2之外的位置。有关这些更改的详细信息,请参阅 ggplot(values, aes(x = "", y = val, fill = T

我正在尝试将标签与带有ggplot2的饼图相匹配:

代码:

值=c(59,4,4,11,26)
标签=c(“catA”、“catB”、“catC”、“catD”、“catE”)
pos=总和(值)-值/2

图形从ggplot2 2.2.0开始,您可以使用
position_stack
vjust=.5
将标签置于堆叠条形图(以及饼图)的中心。您不再需要计算ggplot2之外的位置。有关这些更改的详细信息,请参阅

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")

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")