I want to reduce the display radius of the pie chart built in ggplot2 relative to the rest of the graph (since the default values โโcontinue to crop the labels of my category).
Here are some dummy data and code that should show you what I'm experiencing:
library(ggplot2)
library(scales)
library(grid)
Region <- c("North America", "Central America", "South America", "Carribbean",
"Western Africa", "Northern Africa", "Southern Afica", "Eastern Africa")
Conti <- c(rep("Americas",4), rep("Africa",4))
Freq <- c(runif(8, 1, 100))
Pct <- c(Freq/sum(Freq))
Pos <- c(cumsum(360*Pct)-(360*Pct/2))
Pos <- c(ifelse(Pos<=180,Pos,Pos-180))
df <- data.frame(Region, Conti, Freq, Pct, Pos)
pl <- ggplot(df, aes(x="", y=Freq, fill=Conti)) +
geom_bar(stat="identity", color="black", width=1) +
coord_polar(theta='y') +
guides(fill=guide_legend(override.aes=list(colour=NA))) +
theme(axis.line = element_blank(),
axis.ticks=element_blank(),
axis.title=element_blank(),
axis.text.y=element_blank(),
axis.text.x=element_text(color='black', size=18, angle=90-df$Pos),
panel.background = element_blank(),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.margin = unit(0, "lines"),
plot.background = element_rect(fill = "white"),
plot.margin = unit(c(0, 0, 0, 0), "cm"),
legend.position = "none") +
scale_y_continuous(
breaks=cumsum(df$Freq) - df$Freq/2,
labels=paste0(df$Region," ",percent(df$Pct)))
print(pl)
If I reduce the size of the labels, they will become illegible relative to the cake, and if I increase them, they will be disabled. Regardless of how I try to configure the aes (), limits, panel.margin, etc. parameters, to get the balance, ggplot2 automatically saves the size of the pie to occupy the same radii.
Ideally, I would like to reduce the size of the cake by half, to allow more space for the labels.
, , , . .