Designing a Sankey Chart in SAP Analytics Cloud

Estimated read time 9 min read

A Sankey chart provides an innovative way to represent complex data flows and relationships. Whether it’s showcasing the distribution of resources, understanding the dynamics of a process, or visualising the progression of data through interconnected stages, the Sankey chart goes beyond the constraints of traditional charting solutions. It enables users to uncover hidden patterns, identify bottlenecks, and gain insights into data interconnections that might be ignored with conventional charts. As a result, organisations can make more informed decisions, optimise processes, and enhance overall business performance. The Sankey chart is not a solution directly offered by SAP Analytics Cloud, but an option that can be added through the R Visualization solution from SAC. Let’s explore how to use it!

 

Step 1: Chart creation

To create a Sankey chart in SAC, we will open a story, and go to Insert > + > Others, and select R Visualization.

 

Step 2: Adding a script: a basic version  

When clicking on R Visualization, a chart will automatically be displayed in our layer:

There, we’ll add our input data (modeler or dataset) and our input parameters if needed for a dynamic chart, and the script, that will allow us to display our Sankey chart. Let’s now focus on the script. When selecting Add Script, another panel on the right will be displayed, and we will click on the Expand icon to have a full view:

Now, we have a full view, where the four panels can be adjusted if needed:

In this example, we want to visualise how much the different departments (Marketing, Sales, HR, Finance, Operations, and Customer Service) of a company spend in its several branches. In other words, what kind of expenses does a branch have, and in what proportions. To do so, we’ll copy our code that contains all the information needed for our Sankey chart.

 

 

 

library(‘plotly’)

plot_ly(

type = “sankey”,

orientation = “h”,

node = list(

label = c(“Marketing”, “Sales”, “HR”, “Finance”, “Operations”, “Customer Service”, “Branch 1”, “Branch 2”, “Branch 3”, “Branch 4”, “Branch 5”, “Branch 7”, “Branch 6”),

color = c(“green”, “yellow”, “blue”, “orange”, “red”, “black”, “pink”, “gold”, “violet”, “magenta”, “purple”, “lime”, “cyan”, “silver”),

pad = 15,

thickness = 20,

line = list(

color = “black”,

width = 0.5

)

),

link = list(

source = c(0,0,0,1,1,1,2,2,3,3,4,4,4,5,5,5,5,5),

target = c(9,8,7,8,7,6,7,6,7,6,8,7,6,12,10,8,7,6),

value = c(61.5,34.8,3.46,1.42,8.6,89.7,87.6,12.1,94.6,5.20,96,2.30,1.69,63.1,8.7,15.8,2.81,8.83)

)

)

 

 

And we’ll paste it into the Editor lane, then we’ll click on Execute. If the code works, the Preview lane will display the Sankey chart preview. If not, it will remain empty, and the Console lane will show the errors to be corrected. If the preview works, we will click on Apply and our Sankey chart will be displayed, as in the example below:

As we can see, the expenses of Branch 1 are mostly divided into Sales and HR departments, and to a lesser extent also into Customer Service, Operations, and Finance. Another example would be Branch 3, whose expenses mainly come from the Operations and Marketing departments, but also from the Customer Service and Sales departments in a lower percentage.

 

Step 3: Adding a script: an advanced version  

If you seek to bring a touch of colour to your chart, you just need to add the following line to the previous code (highlighted in green):

 

 

library(‘plotly’)

plot_ly(

type = “sankey”,

orientation = “h”,

node = list(

label = c(“Marketing”, “Sales”, “HR”, “Finance”, “Operations”, “Customer Service”, “Branch 1”, “Branch 2”, “Branch 3”, “Branch 4”, “Branch 5”, “Branch 7”, “Branch 6”),

color = c(“green”, “yellow”, “blue”, “orange”, “red”, “black”, “pink”, “gold”, “violet”, “magenta”, “purple”, “lime”, “cyan”, “silver”),

pad = 15,

thickness = 20,

line = list(

color = “black”,

width = 0.5

)

),

link = list(

source = c(0,0,0,1,1,1,2,2,3,3,4,4,4,5,5,5,5,5),

target = c(9,8,7,8,7,6,7,6,7,6,8,7,6,12,10,8,7,6),

value = c(61.5,34.8,3.46,1.42,8.6,89.7,87.6,12.1,94.6,5.20,96,2.30,1.69,63.1,8.7,15.8,2.81,8.83),

color = c(“blue”, “rgba(255,255,0,0.7)”, “rgba(0,0,255,0.7)”, “rgba(255,165,0,0.7)”, “rgba(255,0,0,0.7)”, “rgba(0,0,0,0.7)”, “rgba(255,192,203,0.7)”, “rgba(255,215,0,0.7)”, “rgba(238,130,238,0.7)”, “rgba(255,0,255,0.7)”, “rgba(128,0,128,0.7)”, “rgba(0,255,0,0.7)”, “rgba(0,255,255,0.7)”, “rgba(192,192,192,0.7)”)

)

)

 

 

In this case, the colour codes are just for example purposes, so feel free to change them for whatever colour you prefer for your chart. Once more, if the Preview lane shows a chart result, click Apply and the Sankey chart will be displayed, as below:

In this last example, the results are the same but the colours help much more to recognise more quickly the percentage of expenses of each department for each branch. For example, the two main big spenders in Branch 2 come from the Finance and HR departments. However, it also has expenses from the Sales department, and at a much lower percentage, from the Operations, Marketing and Customer Service departments. However, Branches 5 and 6 only have one department as an expense: Customer Service. Branch 4 would also only have expenses from the Marketing department.

 

Step 4: Making your Sankey chart dynamic

Last but not least, you can make your Sankey chart dynamic. This way, if your dataset is modified, your chart will be too! To do so, don’t forget to assign your input data, select rows and columns, add filters (if needed), and edit the script!

As a conclusion, the Sankey chart proves to be a valuable asset, allowing organisations to boost data relationships and insights. In a world where data speaks loud, SAP Analytics Cloud, coupled with the dynamic capabilities of Sankey charts, empowers businesses to navigate complex information and make decisions that drive success.

Happy charting!

 

You can also read:

https://blogs.sap.com/2019/10/28/adding-an-interactive-sankey-chart-to-sap-analytics-cloud/

https://blogs.sap.com/2019/08/01/hands-on-tutorial-create-r-visualizations-in-the-sap-analytics-cloud/

 

​ A Sankey chart provides an innovative way to represent complex data flows and relationships. Whether it’s showcasing the distribution of resources, understanding the dynamics of a process, or visualising the progression of data through interconnected stages, the Sankey chart goes beyond the constraints of traditional charting solutions. It enables users to uncover hidden patterns, identify bottlenecks, and gain insights into data interconnections that might be ignored with conventional charts. As a result, organisations can make more informed decisions, optimise processes, and enhance overall business performance. The Sankey chart is not a solution directly offered by SAP Analytics Cloud, but an option that can be added through the R Visualization solution from SAC. Let’s explore how to use it! Step 1: Chart creationTo create a Sankey chart in SAC, we will open a story, and go to Insert > + > Others, and select R Visualization. Step 2: Adding a script: a basic version  When clicking on R Visualization, a chart will automatically be displayed in our layer:There, we’ll add our input data (modeler or dataset) and our input parameters if needed for a dynamic chart, and the script, that will allow us to display our Sankey chart. Let’s now focus on the script. When selecting Add Script, another panel on the right will be displayed, and we will click on the Expand icon to have a full view:Now, we have a full view, where the four panels can be adjusted if needed:In this example, we want to visualise how much the different departments (Marketing, Sales, HR, Finance, Operations, and Customer Service) of a company spend in its several branches. In other words, what kind of expenses does a branch have, and in what proportions. To do so, we’ll copy our code that contains all the information needed for our Sankey chart.   library(‘plotly’)

plot_ly(

type = “sankey”,

orientation = “h”,

node = list(

label = c(“Marketing”, “Sales”, “HR”, “Finance”, “Operations”, “Customer Service”, “Branch 1”, “Branch 2”, “Branch 3”, “Branch 4”, “Branch 5”, “Branch 7”, “Branch 6”),

color = c(“green”, “yellow”, “blue”, “orange”, “red”, “black”, “pink”, “gold”, “violet”, “magenta”, “purple”, “lime”, “cyan”, “silver”),

pad = 15,

thickness = 20,

line = list(

color = “black”,

width = 0.5

)

),

link = list(

source = c(0,0,0,1,1,1,2,2,3,3,4,4,4,5,5,5,5,5),

target = c(9,8,7,8,7,6,7,6,7,6,8,7,6,12,10,8,7,6),

value = c(61.5,34.8,3.46,1.42,8.6,89.7,87.6,12.1,94.6,5.20,96,2.30,1.69,63.1,8.7,15.8,2.81,8.83)

)

)  And we’ll paste it into the Editor lane, then we’ll click on Execute. If the code works, the Preview lane will display the Sankey chart preview. If not, it will remain empty, and the Console lane will show the errors to be corrected. If the preview works, we will click on Apply and our Sankey chart will be displayed, as in the example below:As we can see, the expenses of Branch 1 are mostly divided into Sales and HR departments, and to a lesser extent also into Customer Service, Operations, and Finance. Another example would be Branch 3, whose expenses mainly come from the Operations and Marketing departments, but also from the Customer Service and Sales departments in a lower percentage. Step 3: Adding a script: an advanced version  If you seek to bring a touch of colour to your chart, you just need to add the following line to the previous code (highlighted in green):  library(‘plotly’)

plot_ly(

type = “sankey”,

orientation = “h”,

node = list(

label = c(“Marketing”, “Sales”, “HR”, “Finance”, “Operations”, “Customer Service”, “Branch 1”, “Branch 2”, “Branch 3”, “Branch 4”, “Branch 5”, “Branch 7”, “Branch 6”),

color = c(“green”, “yellow”, “blue”, “orange”, “red”, “black”, “pink”, “gold”, “violet”, “magenta”, “purple”, “lime”, “cyan”, “silver”),

pad = 15,

thickness = 20,

line = list(

color = “black”,

width = 0.5

)

),

link = list(

source = c(0,0,0,1,1,1,2,2,3,3,4,4,4,5,5,5,5,5),

target = c(9,8,7,8,7,6,7,6,7,6,8,7,6,12,10,8,7,6),

value = c(61.5,34.8,3.46,1.42,8.6,89.7,87.6,12.1,94.6,5.20,96,2.30,1.69,63.1,8.7,15.8,2.81,8.83),

color = c(“blue”, “rgba(255,255,0,0.7)”, “rgba(0,0,255,0.7)”, “rgba(255,165,0,0.7)”, “rgba(255,0,0,0.7)”, “rgba(0,0,0,0.7)”, “rgba(255,192,203,0.7)”, “rgba(255,215,0,0.7)”, “rgba(238,130,238,0.7)”, “rgba(255,0,255,0.7)”, “rgba(128,0,128,0.7)”, “rgba(0,255,0,0.7)”, “rgba(0,255,255,0.7)”, “rgba(192,192,192,0.7)”)

)

)  In this case, the colour codes are just for example purposes, so feel free to change them for whatever colour you prefer for your chart. Once more, if the Preview lane shows a chart result, click Apply and the Sankey chart will be displayed, as below:In this last example, the results are the same but the colours help much more to recognise more quickly the percentage of expenses of each department for each branch. For example, the two main big spenders in Branch 2 come from the Finance and HR departments. However, it also has expenses from the Sales department, and at a much lower percentage, from the Operations, Marketing and Customer Service departments. However, Branches 5 and 6 only have one department as an expense: Customer Service. Branch 4 would also only have expenses from the Marketing department. Step 4: Making your Sankey chart dynamicLast but not least, you can make your Sankey chart dynamic. This way, if your dataset is modified, your chart will be too! To do so, don’t forget to assign your input data, select rows and columns, add filters (if needed), and edit the script!As a conclusion, the Sankey chart proves to be a valuable asset, allowing organisations to boost data relationships and insights. In a world where data speaks loud, SAP Analytics Cloud, coupled with the dynamic capabilities of Sankey charts, empowers businesses to navigate complex information and make decisions that drive success.Happy charting! —You can also read:https://blogs.sap.com/2019/10/28/adding-an-interactive-sankey-chart-to-sap-analytics-cloud/https://blogs.sap.com/2019/08/01/hands-on-tutorial-create-r-visualizations-in-the-sap-analytics-cloud/   Read More Technology Blogs by Members articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author

+ There are no comments

Add yours