The code below generates an appropriately stacked bar chart. However, I am trying to add labels to show the percentage in each fill location. With the code below, the percentage labels do not align with the fill boundaries and all "stack" near the 0 point.
This is the code that I used
pff <- read.table(header=TRUE, text='REGION Q99
Tunis NidaaTounes
Tunis Nepasvoter
Tunis Nahdha
Tunis Nepasvoter
Tunis Nahdha
Tunis Nahdha
Tunis NidaaTounes
Tunis Jabha
Tunis NidaaTounes
Tunis Autres
Tunis Nahdha
Tunis Nahdha
Tunis Autres
Tunis Jabha
Tunis Nepasvoter
Tunis Nepasvoter
Tunis CPR
Tunis Nahdha
Tunis Nepasvoter
Tunis Nepasvoter
Ariana Nahdha
Ariana Nepasvoter
Ariana NidaaTounes
Ariana CPR
Ariana NidaaTounes
Ariana NidaaTounes
Ariana NidaaTounes
Ariana CPR
Ariana Nahdha', stringsAsFactors=FALSE)
g <- ggplot(pff, aes(x = REGION, y =(..count..)/sum(..count..), fill=Q99))
g <- g + geom_bar(position="stack") +
labs(title="Vote par région") +
labs(x="", y="")+
labs(fill="Parti Politique")+
coord_flip()+
# scale_fill_manual(values=cbPalette)+
scale_y_continuous(labels = percent)+
theme_bw()+
theme(panel.border = element_rect(colour = "white")) +
geom_text(aes( label = scales::percent((..count..)/sum(..count..)),
y=(..count..)/sum(..count..)), stat= "count", size=3)