I have successfully made a stacked barplot in R where the percentages add up to 100% for several different categories. I made an example dataframe here.
exam
This would give you the asnwer:
ggplot(example.melt, aes(x=example.Category, y=value, fill = variable)) +
geom_bar(position = "fill", stat = "identity",color='black',width=0.9) +
scale_y_continuous(labels = scales::percent) +
geom_text(aes(label = paste0(value*100,"%")),
position = position_stack(vjust = 0.5), size = 2)
Plot would look like this:
You could do something like this...
#set positions for labels
example.melt$labelpos <- ifelse(example.melt$variable=="percent.bad",
example.melt$value/2, 1 - example.melt$value/2)
ggplot(example.melt, aes(x=example.Category, y=value, fill = variable)) +
geom_bar(position = "fill", stat = "identity",color='black',width=0.9) +
scale_y_continuous(labels = scales::percent) +
#use positions to plot labels
geom_text(aes(label = paste0(100*value,"%"),y=labelpos),size = 3)