---
output:
html_document:
code_folding: hide
---
```{r block2, message=FALSE, fig.width=8, fig.height=5, dev='svg'}
library(ggrepel)
cats <- c(CATSDATA)
freq <- c(FREQDATA)
## create data frame
colour.df <- data.frame(cats, freq)
## calculate percentage
colour.df$percentage = colour.df$freq / sum(colour.df$freq)* 100
colour.df = colour.df[rev(order(colour.df$percentage)), ]
colour.df$ymax = cumsum(colour.df$percentage)
colour.df$ymin = c(0, head(colour.df$ymax, n = -1))
donut = ggplot(colour.df, aes(fill = cats, ymax = ymax, ymin = ymin, xmax = 100, xmin = 80)) +
geom_rect(colour = "black") + coord_polar(theta = "y") + xlim(c(0, 100)) +
geom_label_repel(aes(label = paste(round(percentage,2),"%"), x = 100, y = (ymin + ymax)/2),inherit.aes = F, show.legend = F, size = 4) +
theme(legend.title = element_text(colour = "black", size = 12, face = "bold"), legend.text = element_text(colour = "black", size = 10), panel.grid = element_blank(), axis.text = element_blank(), axis.title = element_blank(), axis.ticks = element_blank()) +
theme(panel.background = element_rect(fill="panel.background.fill")) +
annotate("text", x = 0, y = 0, size = annotate.size, label = "annotate.label")
print(donut)