I have successfully made a stacked barplot in R where the percentages add up to 100% for several different categories. The dataframe looks like this:
sujeito teste epentese vozeamento palavra tipo ortografia
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 a n 1 0 cats ts cs
2 b l 1 1 ducks ks cs
3 c l 1 1 cups ps cs
4 d l 0 0 grapes ps ces
5 e l 1 0 lakes ks ces
6 f n 1 0 gates ts ces
7 g n 0 0 books ks cs
8 h n 1 0 cakes ks ces
9 a n 1 1 kites ts ces
10 b n 1 0 boats ts cs
Then I used ggplot and deplyr to make a stacked barplot displaying these percentages. I used this code:
dados%>%
group_by(sujeito, epentese)%>%
summarise(quantidade = n())%>%
mutate(frequencia = quantidade/sum(quantidade))%>%
ggplot(., aes(x = sujeito, y = frequencia, fill = epentese))+
geom_col()+
geom_col(position = position_fill(reverse=TRUE))+
scale_y_continuous(labels=scales::percent)+
labs(title = "Epenthesis rates by subject")+
theme(plot.title = element_text(hjust = 0.5))+
xlab("Subject")+ylab("Frequency")
My intention, though, is to make it as the graph of the right side of this picture:
I have tried different packages and also manipulating geom_text, but still no luck, especially due to the fact that I don't need the labels of both "fill categories", just the red one. I hope this isn't too redundant. Thanks in advance!