Top 10 Countries in Olympics: Sankey Diagram

Data Visualization
R
Author

Venkata Nekkanti

Modified

June 7, 2025

Objective:

The goal is to create an interactive, easy-to-understand visualization of the medal counts for the top 10 countries in the Olympics, highlighting both the total number of medals and the breakdown by type (Gold, Silver, Bronze). Users can explore how medals flow from types (Gold, Silver, Bronze) to the countries that earned them.

library(tidyverse)
library(networkD3)
library(htmlwidgets)

Code:

# Input data
medal_data <- data.frame(
  Nation = c("United States", "Russia", "Germany", "China", "Great Britain", 
             "France", "Italy", "Sweden", "Norway", "Japan"),
  Gold = c(1219, 748, 617, 325, 310, 280, 271, 216, 213, 206),
  Silver = c(1000, 634, 625, 258, 344, 320, 244, 232, 187, 191),
  Bronze = c(876, 627, 617, 221, 360, 354, 284, 242, 176, 221)
)

# Pivoted the data to long format for Sankey diagram
medal_long <- medal_data  |> 
  pivot_longer(cols = c(Gold, Silver, Bronze), 
               names_to = "Medal", 
               values_to = "Count")

medals <- unique(medal_long$Medal)
countries <- medal_data$Nation

nodes <- data.frame(
  name = c(medals, countries)
)

links <- medal_long |> 
  mutate(
    source = match(Medal, nodes$name) - 1,
    target = match(Nation, nodes$name) - 1,
    value = Count
  ) |> 
  select(source, target, value)

# Create the Sankey diagram
sankey_chart <- sankeyNetwork(
  Links = links, 
  Nodes = nodes,
  Source = "source", 
  Target = "target",
  Value = "value", 
  NodeID = "name",
  sinksRight = FALSE,
  nodeWidth = 30,
  nodePadding = 10,
  height = 600,
  width = 800,
  fontSize = 14,
  margin = list(left = 0, right = 0)
)

Output:

This visualizes the Olympic medal distribution for the top 10 countries using a Sankey diagram. The diagram shows how many Gold, Silver, and Bronze medals each country won. On the left side, you’ll see the medal types, and on the right, the countries.

Gold → United States
1,219 
Silver → United States
1,000 
Bronze → United States
876 
Gold → Russia
748 
Silver → Russia
634 
Bronze → Russia
627 
Silver → Germany
625 
Gold → Germany
617 
Bronze → Germany
617 
Bronze → Great Britain
360 
Bronze → France
354 
Silver → Great Britain
344 
Gold → China
325 
Silver → France
320 
Gold → Great Britain
310 
Bronze → Italy
284 
Gold → France
280 
Gold → Italy
271 
Silver → China
258 
Silver → Italy
244 
Bronze → Sweden
242 
Silver → Sweden
232 
Bronze → China
221 
Bronze → Japan
221 
Gold → Sweden
216 
Gold → Norway
213 
Gold → Japan
206 
Silver → Japan
191 
Silver → Norway
187 
Bronze → Norway
176 
Gold
4,405
Gold
Silver
4,035
Silver
Bronze
3,978
Bronze
United States
3,095
United States
Russia
2,009
Russia
Germany
1,859
Germany
China
804
China
Great Britain
1,014
Great Britain
France
954
France
Italy
799
Italy
Sweden
690
Sweden
Norway
576
Norway
Japan
618
Japan

Inspired from Yan Holtz’s Data-to-Viz