v1 = c("Sim","Não","Não","Não","Não","Sim","Sim","Sim","Sim","Sim")
v2 = c("branco","branco","pardo","preto","pardo","pardo","preto","branco","preto","pardo")
dados = data.frame(v1,v2)
I want to build a bar chart with relative frequencies totaling 100% within each category of variable v1 (Yes / No).
I tried this way:
ggplot(dados,aes(x=as.factor(v2),y=percent())) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
geom_text(aes(y = ((..count..)/sum(..count..)),
label=scales::percent((..count..)/sum(..count..))),stat="count", vjust = -0.25)+
scale_y_continuous(labels = percent) + labs(y = "Percentual",x="Raça/Cor")+
facet_grid(.~v1)
But it is not totaling 100% within each category of v1. Any help?