图表内的文字

text inside the chart

我有一个名为 seed_l_Last_fiscal_yr_m

的数据集
mycols <- c("#CD534CFF","#0073C2FF", "#EFC000FF", "#868686FF", "#CD534CFF")
text="Donor Details"

ggplot(seed_b_Last_fiscal_yr_m, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=donor)) +
  geom_rect() +
  scale_fill_manual(values = mycols) +
  coord_polar(theta="y")+
  xlim(c(2, 4))+
  theme_void()

您可以使用annotate功能。请注意,您必须将 x = 值设置在 xlim() 设置的限制内。

ggplot(seed_b_Last_fiscal_yr_m, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=donor)) +
  geom_rect() +
  annotate("text",x = 2, y = 0, label = text, size = 5, color = "black") +
  scale_fill_manual(values = mycols) +
  coord_polar(theta="y") + 
  xlim(2,4) + 
  theme_void()

示例数据:

seed_b_Last_fiscal_yr_m <- structure(list(donor = c("TLF", "TLF", "RF/ TDP", "RF/ TDP", 
"RF/ TDP", "RF/ TDP", "RF/UCID", "RF/UCID"), amount = c(7L, 15L, 
8L, 5L, 7L, 15L, 10L, 9L), ymax = c(0.02991453, 0.09401709, 0.12820513, 
0.14957265, 0.17948718, 0.24358974, 0.28632479, 0.32478632), 
    ymin = c(0, 0.02991453, 0.09401709, 0.12820513, 0.14957265, 
    0.17948718, 0.24358974, 0.28632479)), class = "data.frame", row.names = c(NA, 
-8L))