So I have a pie chart of many hpv subtypes and that's problematic, because some are like 1% and the percentage label doesn't fit. So I was wondering how could I move the % label outside of the pie chart so it can be readable?
My code is this:
#Creating my data frame
HPV <- c("HPV16","HPV18","HPV45","HPV58","HPV68","HPV52","HPV31","HPV39","HPV30","HPV33","HPV56","HPV59","HPV73","HPV35","HPV70","HPV69")
proportion <- c(0.609467456,0.159763314,0.059171598,0.029585799,0.00591716,0.029585799,0.017751479,0.017751479,0.00591716,0.017751479,0.00591716,0.017751479,0.00591716,0.00591716,0.00591716,0.00591716)
df<-data.frame(HPV,proportion)
library(ggplot2)
#Creating the pie chart
pie <- ggplot(data = df, aes(x="", y=proportion, fill=HPV)) +
geom_col(color = "black") +
coord_polar("y", start=0) +
geom_text(aes(label=paste0(round(proporción*100), "%")),
position = position_stack(vjust=0.5)) +
theme(panel.background = element_blank(),
axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5, size = 18)) +
ggtitle("Subtypes of HPV in GDC TCGA cervical cancer (CESC)") +
scale_fill_manual(values = c("#F46698","#F36DDB","#DD6DF3","#AC6DF3","#7355FC","#5562FC","#5562FC","#55B5FC","#55C7FC","#55E8FC","#56EDEB","#93F9EF","#61F9BF","#5BEC75","#58D64B","#91D64B","#B4D64B","#D6D64B","#FFDB57"))
print(pie)