I have created a pie chart with ggplot in R plotting "Amounts" for 7 companies (A to G).
The data and code are the following:
# Data
data=data.frame('Company'=(c("A","B","C","D","E","F","G")),'Amount'=c(30,20,10,5,5,2,1))
data=data %>% mutate(Company= factor(x = Company, levels = Company)) %>%
mutate(prop = Amount / sum(data$Amount) ) %>% mutate(ypos = cumsum(prop)- 0.5*prop )
# Pie chart
library(ggplot2)
ggplot(data, aes(x="", y=Amount, fill= Company) )+
geom_bar(width = 1, stat = "identity") + coord_polar("y", start=0,direction = -1) + theme_void() +
#geom_text(aes(label = percent(prop) ), size=3, position=position_stack(vjust=0.5)) +
labs(x = NULL, y = NULL, fill = NULL) + scale_fill_brewer(palette="Blues", direction=-1) +
geom_text(aes(label = percent(prop) ), size=3, position=position_stack(vjust=0.5))
However, the labels for F and G are stacked on each other such that we can't read the values properly.
I would like to place those labels in the legend such that the legend reads as: A (41.1%) B (27.4%) C (13.7%) etc.