Search code examples
rggplot2polar-coordinates

text inside the chart


I have a dataset named 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()

Solution

  • You can use the annotate function. Note that you must set the x = value to be within the limits set by 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()
    

    enter image description here

    Sample Data:

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