0

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()
s_baldur
  • 29,441
  • 4
  • 36
  • 69
Fariya
  • 234
  • 1
  • 11
  • 1
    Welcome to Stack Overflow! Can you please read and incorporate elements from [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Especially the aspects of using `dput()` for the input and then an explicit example of your expected dataset? – wibeasley Dec 09 '20 at 15:43

1 Answers1

0

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))
Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
  • thanks alot............but how to use this line sum(seed_l_Last_fiscal_yr_m[seed_l_Last_fiscal_yr_m$type=="Actual",]$amount) and i get 76 inside the chart how to update this value – Fariya Dec 09 '20 at 15:53
  • The data you present in the question does not appear to have a column `type`. There should be no reason that you cannot use `sum` to calculate the value for `label = ` in `annotate`. For example `annotate("text",x = 2, y = 0, label = paste0(text,"\n",sum(seed_b_Last_fiscal_yr_m$amount)), size = 5, color = "black")`. – Ian Campbell Dec 09 '20 at 15:56
  • i have type value in another dataframe so how to use inside this plot @ – Fariya Dec 09 '20 at 16:04
  • I don't think it's possible to answer this without an example of the data. If you have a different question, I would recommend posting it with the [Ask Question](https://stackoverflow.com/questions/ask) button. – Ian Campbell Dec 09 '20 at 16:12
  • i update the second dataframe but u just plzz edit that so that it will be more readable – Fariya Dec 09 '20 at 16:19