I have a dataset with the number of impressions from a unique user and whether this user has been converted = 1, or not (=0). I want to create a col chart that displays the conversion rate for intervals of 20 impressions. Meaning that for each interval, the conversion rate is the number of converted users in that interval of impressions, divided by the number of unique users in that interval.
So for instance, for this dataset:
# A tibble: 19 x 2
converted tot_impr
<dbl> <dbl>
1 0 19
2 0 4
3 1 19
4 0 13
5 0 18
6 1 9
7 1 17
8 1 8
9 1 8
10 1 11
11 0 8
12 0 19
13 1 8
14 0 8
15 1 18
16 0 12
17 1 5
18 1 12
19 0 1
I should be seeing those conversion rates:
I have managed to count the number of converted users per interval using ggplot2 geom_col using the following code:
ggplot(data = db) +
geom_col(mapping = aes(x = tot_impr, y = converted), width=5)
I am struggling to force geom_col
to display not the converted count in the y-axis, but to display the percentage of converted in relation to the total number of individual samples in that interval of impressions.
Could someone help me out?
Thank you in advance!