R 在饼图2上贴上标签

R 在饼图2上贴上标签,r,ggplot2,pie-chart,labels,R,Ggplot2,Pie Chart,Labels,我的df看起来像: 1 with score 125 without score 我想在ggplot中制作piechart: ggplot(data = df_pp, aes(x = "", y = Number/sum(Number),fill = PolyPhen_score)) + geom_bar(stat="identity") + coord_polar(theta='y') + ggtitle("Variants with PolyPhen score and wi

我的df看起来像:

1   with score
125 without score
我想在ggplot中制作piechart:

ggplot(data = df_pp, aes(x = "", y = Number/sum(Number),fill =     PolyPhen_score)) + geom_bar(stat="identity") + coord_polar(theta='y')  +
ggtitle("Variants with PolyPhen score and without PolyPhen score") + 
scale_y_continuous(labels  = percent) + labs(x = "", y = "") +
theme(panel.background = element_rect(fill = 'white')) + 
geom_text(aes(label = paste(round(Number/sum(Number)*100),"%")),vjust = 5)
但是我的标签1%和99%在图表上重叠了

如果我添加此代码,则没有帮助:

geom_text(aes(y=Number/2 + c(0,cumsum(Number)[-length(Number)]), label = percent(Number/100)), size=5)

也许这些其他问题可以帮助您:

  • 我用一些随机数据在我的机器上做了一些测试,并尝试了以下方法:

    geom_text(aes(x = 1.7, y=cumsum(Number/sum(Number)) - Number/sum(Number)/2, label = paste(round(Number/sum(Number)*100),"%")), size = 6)
    

    X
    是标签与饼图中心的距离
    x=1.7
    在RStudio中为我的数据提供了一个很好的结果,但您可能需要不同的值

    在帖子中添加数据,
    dput(df\u pp)