I want to visualize a typical customer's journey using Python or R. As usual, customers buy different products at different points of time.

I checked every customers journey and chose product A as a starting point. 10,000 customers bought product A as their first product. Now I want to show the "flow" of their journey. After 10 minutes, 2,500 of these 10,000 customers, bought product B as their second product. Product C was bought by 7,500 people after 25 minutes.

I am looking for a more complex sankey chart. You start of with a bar chart with the height of 10,000 on the left. There are two bar charts on the right and you see a connection between the left and right charts. The longer it took the customers to buy the next product, the further away are the bars on the right from the left one. All the bars have titles with their product names. Quick infos on the charts would also be nice.

The final chart would visualize a longer customer journey (more than two products).

What I have tried

I used the networkD3 R package to visualize a sankeyNetwork, however I could not place the bar charts according to my desires.

Do you have any recommendations for Python or R packages, or is there a way to draw it by myself (in a reasonable amount of time)?

  • $\begingroup$ There are going to be a large number of paths connecting two end points, so you will have to limit the visualization to the most popular paths. I don't know of any off-the-shelf solutions; I recommend taking the best package you can find and extending it. $\endgroup$
    – Emre
    Jun 26, 2017 at 17:49

1 Answer 1


This may be too simple for what you had in mind, but perhaps it will help:

Example data

library(tidyverse); library(magrittr) # load R libraries
sample_data = data.frame(Customer = 1:100, A = 0, B = rep(c(10,NA), c(25,75)), C = rep(c(NA,25), c(25,75))) 

Bar chart

sample_data %>% gather("Product", "Time", -Customer) %>% ggplot()+geom_bar(aes(x=Time, fill=Product))+geom_label(aes(x=Time, label=Product), y=-Inf, vjust=0)

enter image description here

Point plot

The use of this is that you can map the customers (since the y-axis is not the count but the Customer ID), i.e., you can add lines connecting them but they would be too many, so I haven't (they can be grouped though, for A->B, B->C, A->C, etc)

sample_data %>% gather("Product", "Time", -Customer) %>% ggplot()+geom_point(aes(x=Time, y=Customer, color=Product))+geom_label(aes(x=Time, label=Product), y=-Inf, vjust=0)

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.