Visualizing business flows with Shankey diagrams - Hive revenue structure analysis example
Hundreds of thousands of soldiers were lost in Napoleon's Russian expedition of 1812, and a great visual representation of this is the Sankey Diagram. This diagram, which intuitively communicates each ratio by showing the start and end of the data flow with the thickness of the line, is very useful for visualizing the revenue and cost structure of your business.

In this post, we'll use the Options and usage of the SankeyNetwork packageand represent Hive's Q3 2024 revenue structure in a Shankey diagram. So, let's get started with drawing a Shankey diagram.
What is a biometric network?
The keynetwork (SankeyNetwork) is a visual representation of data flow and proportions in R's networkD3 package function. In drawing a Shankey diagram, the start and end of each flow and the thickness of the connecting lines represent the proportion of data that makes up the flow. The thickness of each flow gives you an intuitive understanding of the amount and direction of data, which is great for analyzing business revenue and expense flows.
Introducing the basic skeleton and key options of the Shanky Network
There are a few key elements and options you need to know about when drawing a Shankey diagram. We'll explain them in a way that's easy to understand, even for beginners.
- Nodes: Define the starting and ending points of the data. Each node represents a specific point, which can be represented by text or name.
- LinksLines connecting each node, representing the flow of data. For example, a link from "Total revenue" to "Recordings/Music" represents a portion of that revenue.
- source and target: Specifies where the link is going from, where source refers to the originating node and target refers to the destination node.
- value: A value that determines the thickness of the link, the higher the value, the thicker the connection. This allows you to visually emphasize the size of the flow.
- NodeIDOptions to define the text to display on each node.
- unitsDefine the units displayed to make the data more intuitive to understand.
- Other style options:
- fontSize: Specifies the font size for nodes and links.
- nodeWidthYou can adjust the width of the : node to make it more readable.
Hive's Q3 2024 revenue and cost structure data
To represent the flow of revenue and expenses in the hive as a Shankey diagram, we'll use the following data
1. Total sales: KRW 527.8 billion
- Discography/Soundtracks: KRW 214.4 billion
- Performances: KRW 73.9 billion
- Ads/Fuel: 34.4 billion won
- MD and licensing: 99.1 billion won
- Content: KRW 79.7 billion
- Fan clubs: 25.9 billion won
2. Gross profit: KRW 240.4 billion (45.51 TP3T of total revenue)
3. Operating Profit: KRW 54.1 billion (10.21 TP3T of total revenue)
4. Operating expenses: KRW 186.2 billion
- Labor costs: 95.6 billion won
- Non-operating losses: KRW 52.7 billion
- Transportation costsKRW 12.2 billion
- Amortization: 19.7 billion won
- Royalties and other feesKRW 14.4 billion
5. Net Profit: KRW 1.4 billion (0.21 TP3T of total revenue)
Install the SankeyNetwork package and prepare your data
Now let's try drawing a Sankey diagram. We'll use the networkD3 package and the SankeyNetwork function to prepare our data.
Install and load the # package
if (!require("networkD3")) { {
install.packages("networkD3")
}
library(networkD3)
Generate # Hive revenue structure data
nodes <- data.frame(name = c("Total Revenue", "Album/Digital", "Concert", "Advertisement", "MD & Licensing",
"Content", "Fan Club", "Gross Profit", "Operating Profit", "Operating Expenses", "Net Profit",
"Non-operating Loss", "Labor Cost", "Transportation", "Depreciation", "Rent/Management",
"Commission", "Other Admin")))
Modify the source and target of # links to indexes starting at 0
links <- data.frame(
source = c(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 8, 8, 8, 8, 8, 8, 8, 8, 8),
target = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17),
value = c(2144, 739, 344, 991, 797, 259, 2404, 1862, 541, 14, 527, 956, 122, 197, 144, 363, 78)
)Code description:
- Installing and loading packages:
networkD3Check to see if the package is installed, and if not, proceed with the installation.library(networkD3)command to load the package.
- Create a data frame:
nodesDataframe: Define the names of the nodes (components) that will be used in the shanky diagram.- It consists of 18 nodes, including total revenue, each revenue/expense item, and more.
- Create a link dataframe:
linksDataframe: Defines the connections between nodes and the amount information.
Drawing Sankey Diagrams with the SankeyNetwork Function
Now let's visualize the data we've prepared with the SankeyNetwork function.
Create a # Sankey diagram
sankey <- sankeyNetwork(Links = links,
Nodes = nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "name",
units = "billion KRW",
fontSize = 12,
nodeWidth = 30)
Display the # diagram
print(sankey)Code description:
- Create a Shankey diagram:
sankeyNetwork()function to generate a Shankey diagram.- We pass the following arguments
Links = links: Passes the link dataframe you prepared earlier.Nodes = nodes: Pass in the node dataframe you prepared earlier.Source = "source": means you want to use the source column of the links dataframe.Target = "target": means you want to use the target column of the links dataframe.Value = "value": means you want to use the value column of the links dataframe.NodeID = "name": nodes means that you want to use the name column of the dataframe as the node name.units = "billion KRW"means that you want to display the amount unit as "Billion KRW".fontSize = 12: Set the font size of nodes and links to 12.nodeWidth = 30Set the width of the : node to 30.
- Show diagrams:
print(sankey)Print/display the Shankey diagram generated by the command.

Wrapping up: Intuitive business analysis with Shankey diagrams
Visualizing Hive's revenue structure as a Sankey diagram reveals the complex revenue flow. SankeyNetwork is a great way to intuitively represent business revenue and expense flows. If you too want to easily represent complex data, give this package a try.
As a side note, we've been hearing a lot about neural networks lately, even though they're not as exciting as Shankey diagrams, but have you ever wanted to see one in action? Is it just me? Drawing Neural Networks in R: Understanding Neural Network Structure with Line-by-Line Explanations (feat. neuralnet) Would you like to see the post? It's almost as fun as drawing a shanky diagram.




