无法将标签添加到带有ggplot2的piechart

无法将标签添加到带有ggplot2的piechart,r,ggplot2,pie-chart,R,Ggplot2,Pie Chart,有人能给我解释一下为什么我不能给这个饼图添加标签吗 > dput (test) structure(list(Status = c("Isolamento domiciliare", "Ricoverati con sintomi", "Terapia intensiva", "Deceduti", "Dimessi guariti"), label = c("69.03%", "17.70%", "12.39%", "0.88%", "0.00%"), value = c(78, 2

有人能给我解释一下为什么我不能给这个饼图添加标签吗

> dput (test)
structure(list(Status = c("Isolamento domiciliare", "Ricoverati con sintomi", 
"Terapia intensiva", "Deceduti", "Dimessi guariti"), label = c("69.03%", 
"17.70%", "12.39%", "0.88%", "0.00%"), value = c(78, 20, 14, 
1, 0)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame"
))
这是im用于绘图的代码:

ggplot(test, aes(x="", y=value, fill=Status)) +
    geom_bar(stat="identity", width=1, color="white") +
    coord_polar("y", start=0) +
    theme_void()+ labs(fill = "Situazione attuale")

提前感谢

使用极坐标,您需要为标签定义一些位置。在这里,我们可以将这些位置定义为:

库(dplyr)
测试2%
排列(描述(状态))%>%
变异(百分比=值/总和(值)*100)%>%
突变(ypos=cumsum(百分比)-0.5*百分比)
#一个tibble:5x5
状态标签值百分比ypos
1千兆帕强度12.39%1412.46.19
2圣多米米饭17.70%20 17.7 21.2
3伊索拉门托居民69.03%78 69.0 64.6
4维瓜里蒂0.00%0.99.1
12月5日0.88%1 0.885 99.6
然后,可以将此标签添加到绘图中。但是,由于值非常接近(0和0.88%),这些值可能会重叠。因此,您可以使用
geom_text_repel
,但它也会更改其他标签的位置。因此,我决定将大值添加为常规
geom_text
,将小值添加为
geom_text_repel
,得到以下结果:

库(ggrepel)
图书馆(GG2)
ggplot(测试2,aes(x=”,y=百分比,填充=状态))+
几何图形条(stat=“identity”,width=1,color=“white”)+
坐标(y),起点=0)+
theme_void()+实验室(fill=“Situazione attuale”)+
geom_文本(数据=子集(test2,值>2),aes(label=label,y=ypos))+
几何图形文本排斥(数据=子集(测试2,值2),aes(标签=标签,y=ypos,颜色=状态),show.legend=FALSE,x=1.75)+

几何体文本排斥(数据=子集(test2,value我不能复制你的问题。这在旁边给了我一个很好的图例。这不是你想要的吗?这很有帮助,谢谢你!但我想最好把标签贴在外面,你怎么看?原始问题中没有提到,所以我猜不出你在找什么。我根据让我知道它是否适合你。谢谢你!!你是最棒的。