# Load necessary libraries
library(networkD3)
# Read the data
sankey_data <- read.csv("C:/Users/geeth/Downloads/Sankey_Data.csv")
# Prepare unique nodes
nodes <- data.frame(name = unique(c(sankey_data$Company, sankey_data$job_type)))
# Map source and target to node indices
links <- data.frame(
source = match(sankey_data$Company, nodes$name) - 1,
target = match(sankey_data$job_type, nodes$name) - 1,
value = sankey_data$layoffs
)
sankey <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
units = "Layoffs", fontSize = 12, nodeWidth = 30)
sankey