I am trying to display percentages as labels inside bars of an overlaid graph in ggplot2. I found another post from 3 years ago, but I can’t reproduce it: How to draw stacked columns in ggplot2 showing percentages for a group?
The answer to this post is almost what I'm trying to do.
Here is a simple example of my data:
df = data.frame('sample' = c('cond1','cond1','cond1','cond2','cond2','cond2','cond3','cond3','cond3','cond4','cond4','cond4'),
'class' = c('class1','class2','class3','class1','class2','class3','class1','class2','class3','class1','class2','class3'))
ggplot(data=df, aes(x=sample, fill=class)) +
coord_flip() +
geom_bar(position=position_fill(reverse=TRUE), width=0.7)

I would like for each bar to show a percentage / share, so in this case they will all be 33%. In fact, it would be nice if the values were calculated on the fly, but if necessary, I can manually transfer percentages. Can anyone help?
: ? , width position_fill(), .
!
EDIT:
, , ( ), , . , , :
df = data.frame('sample' = c('cond1','cond1','cond1','cond2','cond2','cond2','cond3','cond3','cond3','cond4','cond4','cond4','cond1'),
'class' = c('class1','class2','class3','class1','class2','class3','class1','class2','class3','class1','class2','class3','class2'))
, /.