I have this chart.
g <- retention_cohorts %>%
ggplot(aes(relative_week, round(percent,2), label=relative_week)) +
geom_line() +
scale_y_continuous(labels = percent) +
scale_x_continuous(breaks = seq(1,24,4),
labels = seq(1,6)
) +
geom_text(nudge_y = .02) +
labs(
title = "Purchasing Retention Analysis",
subtitle = "Customers who order at least one item each week",
y = "Customers with at least One Purchase",
x = "Relative Month"
) + theme_light()
It's a great chart and I want to make it interactive. When I use ggplotly(g)
, it recreates it almost perfectly except that it drops the subtitle. Is there a way to force it to keep the subtitle or to add new text as a subtitles after the plotly
entity has been created?
This helped me, Subtitles with ggplotly. Seems any text such as annotations or subtitles added to ggplot must be put after the ggplotly function into a layout function.
plot <- retention_cohorts %>%
ggplot(aes(relative_week, round(percent,2), label=relative_week)) +
geom_line() +
scale_y_continuous(labels = percent) +
scale_x_continuous(breaks = seq(1,24,4),
labels = seq(1,6)) +
geom_text(nudge_y = .02) +
labs(y = "Customers with at least One Purchase",
x = "Relative Month") +
theme_light()
ggplotly(plot) %>%
layout(title = list(text = paste0('Purchasing Retention Analysis',
'<br>',
'<sup>',
'Customers who order at least one item each week','</sup>')))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With