Some data:
sub_funnel_data <- structure(list(funnelstep = structure(1:5, .Label = c("Sessions",
"Engaged Sessions", "Subscription Funnel - Arrives on Enter Email",
"Subscription Funnel - Arrives on Payment Details", "Direct to Paid"
), class = "factor"), N = c(92853L, 33107L, 3469L, 3149L, 113L
), Drop = c(NA, 0.356552830818606, 0.104781466155194, 0.907754396079562,
0.0358844077484916), Rate = c(1, 0.356552830818606, 0.0373601283749583,
0.0339138207704651, 0.00121697737283663)), row.names = c(NA,
5L), class = c("tbl_df", "tbl", "data.frame"))
Looks like:
sub_funnel_data
# A tibble: 5 x 4
funnelstep N Drop Rate
* <fct> <int> <dbl> <dbl>
1 Sessions 92853 NA 1
2 Engaged Sessions 33107 0.357 0.357
3 Subscription Funnel - Arrives on Enter Email 3469 0.105 0.0374
4 Subscription Funnel - Arrives on Payment Details 3149 0.908 0.0339
5 Direct to Paid 113 0.0359 0.00122
I can create a plot:
sub_funnel_data %>%
ggplot(aes(reorder(funnelstep, desc(funnelstep)), N)) +
geom_bar(stat = 'identity', fill = '#39cccc') +
coord_flip()
I would like to add the drop in percentage on each step to this chart. Similar to a question I posted a few years back.
I tried to modify the solution there to my needs but failed. I like the outcome of that solution, the only real difference is that now my plot is flipped.
Here's what I tried:
sub_funnel_data <- sub_funnel_data %>% mutate(End = lag(N),
xpos = 1:n() - 0.5,
Diff = End - N,
Percent=paste(round(Diff / End * 100, 1), "%"))
Then my attempted plot:
Before coord_flip()
:
sub_funnel_data %>%
ggplot(aes(reorder(funnelstep, desc(funnelstep)), N)) +
geom_bar(stat = 'identity', fill = '#39cccc') +
stat_summary(aes(label = scales::comma(..y..)), fun = 'sum',
geom = 'text', col = 'white', vjust = 1.5) +
geom_segment(aes(x=xpos, y = End, xend = xpos, yend = N)) +
geom_text(aes(x = xpos, y = End - Diff / 2, label = Percent), hjust = -0.2)
I can already see this is flawed. But I want to use it with coord_flip()
anyway:
sub_funnel_data %>%
ggplot(aes(reorder(funnelstep, desc(funnelstep)), N)) +
geom_bar(stat = 'identity', fill = '#39cccc') +
stat_summary(aes(label = scales::comma(..y..)), fun = 'sum',
geom = 'text', col = 'white', vjust = 1.5) +
geom_segment(aes(x=xpos, y = End, xend = xpos, yend = N)) +
geom_text(aes(x = xpos, y = End - Diff / 2, label = Percent), hjust = -0.2) +
coord_flip()
How can I add percentage drop off on each step to my chart? Ideally I'd like to use the Rate
field in sub_funnel_data
to display the corresponding percentage drop between each step. I like the lines and %ages shown at the midpoint on each chart in the linked post, I just cannot replicate it to my current use case.