I have a question about a possibility to specifying a layout of pie chart. Let's take the code following
pie_chart=function(vec,save){
if (class(vec)=='numeric'){vec<-as.character(vec)
vec<-print(paste('var',vec))
}
df<-data.frame(table(vec))
colnames(df)[1]<-'group'
bp<- ggplot(df, aes(x="", y=Freq, fill=group))+
geom_bar(width = 1, stat = "identity")
blank_theme <- theme_minimal()+
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.border = element_blank(),
panel.grid=element_blank(),
axis.ticks = element_blank(),
plot.title=element_text(size=14, face="bold")
)
pie <- bp + coord_polar("y", start=0)
pie + scale_fill_brewer("Characteristic") + blank_theme +
theme(axis.text.x=element_blank())+
geom_text(aes(y = Freq/3 + c(0, cumsum(Freq)[-length(Freq)]),
label = print(paste0(Freq,'(',percent(Freq/(sum(Freq))),')'))), size=5)
}
pie_chart(c(rep(1,50),rep(2,60),rep(3,26),rep(4,24)))
And as you can see at the picture above, labels are placed in weird way. Is there any easy way how can I center them into a 'middle of part of the pie' ?
Thanks in advance !