Aquí un ejemplo:
The issue is that ggplot doesn’t know that each facet is one group. This very useful tutorial helps with a nice solution. Just add aes(group = 1)
P.S. At the beginning, I was often quite reluctant and feared myself to manipulate my data and pre-calculate data frames for plotting. But there is no need to fret! It is actually often much easier (and safer!) to first shape / aggregate your data into the right form and then plot/ analyse the new data.
ds <- mtcars ds$gear <- as.factor(ds$gear) First solution: ggplot(ds, aes(gear, fill = gear)) + geom_bar() + facet_grid(cols = vars(cyl), margins = T) + geom_text(aes(label = scales::percent(..prop..), group = 1), stat= "count")