I have a dataframe d
:
> head(d,20)
groupchange Symscore3
1 4 1
2 4 2
3 4 1
4 4 2
5 5 0
6 5 0
7 5 0
8 4 0
9 2 2
10 5 0
11 5 0
12 5 1
13 5 0
14 4 1
15 5 1
16 1 0
17 4 0
18 1 1
19 5 0
20 4 0
That I am plotting with:
ggplot(d, aes(groupchange, y=..count../sum(..count..), fill=Symscore3)) +
geom_bar(position = "dodge")
In this way each bar represents its percentage on the whole data.
Instead I would like that each bar represents a relative percentage; i.e. the sum of the bar in obtained with groupchange = k
should be 1
.
..count..
) was deprecated in ggplot2 3.4.0. ℹ Please useafter_stat(count)
instead. // i.e y=after_stat(count)/sum(after_stat(count) – Osprey