Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用ggplot2将文本标签放入饼图的相应部分_R_Ggplot2 - Fatal编程技术网

R 使用ggplot2将文本标签放入饼图的相应部分

R 使用ggplot2将文本标签放入饼图的相应部分,r,ggplot2,R,Ggplot2,我有下面的数据框,我使用ggplot2创建了apie图表,但文本标签不在正确的切片内,有些标签彼此重叠。我也需要文本不重叠彼此 HU2<-c(1, 2, 4, 5, 7, 8, 9, 10, 11) Freq<-c(5118, 2226, 5817, 159, 6766, 27, 984, 654, 89) Abs_Freq<-c("0.23", "0.10", "0.27", "

我有下面的数据框,我使用ggplot2创建了apie图表,但文本标签不在正确的切片内,有些标签彼此重叠。我也需要文本不重叠彼此

HU2<-c(1,  2,  4,  5,  7,  8,  9,  10, 11)
Freq<-c(5118, 2226, 5817,  159, 6766,   27,  984,  654,   89)
Abs_Freq<-c("0.23", "0.10", "0.27", "0.01", "0.31", "0.00", "0.05", "0.03", "0.00")
df$label <- scales::percent(as.numeric(df$Abs_Freq))

p2<-ggplot(data=df)+
  geom_bar(aes(x="", y=as.numeric(Abs_Freq), fill=HU2), stat="identity", width = 1)+
  coord_polar("y", start=0)+
  theme_void()+
  geom_text(aes(x=1, y = cumsum(as.numeric(Abs_Freq)) - as.numeric(Abs_Freq)/2, label=label))
p2

在使用极坐标之前,通常最容易诊断笛卡尔空间中的饼图问题。在这种情况下,您可以使用
position=position\u stack()
将文本放置在右侧楔块中,而不是手动计算累积频率。请注意,如果要按预期进行堆叠工作,则文本和栏中的
也应相同

库(ggplot2)

这能回答你的问题吗?