year | urban | cropland | pasture | forest | scrubland | no vegetation | water |
---|---|---|---|---|---|---|---|
1900 | 1086 | 11088 | 1094 | 24623 | 14774 | 167 | 844 |
1924 | 1142 | 11242 | 1256 | 23939 | 15091 | 162 | 844 |
1948 | 1225 | 12451 | 1460 | 22430 | 15105 | 161 | 844 |
1972 | 1986 | 16278 | 3789 | 20808 | 9855 | 116 | 844 |
1996 | 2794 | 16165 | 3792 | 18604 | 11350 | 127 | 844 |
2019 | 3194 | 19713 | 3823 | 17742 | 8266 | 94 | 844 |
i want to show difference from by using sankey digram year by year 1900,1924,1948,1972,1996,2019. can you help me someone?
my code but it doesnt work
ibrary(networkD3)
Data
data <- data.frame(
Year = c(1900, 1920, 1940, 1960, 1980, 2000, 2019),
Urban = c(1086, 1126, 1196, 1501, 2290, 2857, 3194),
Cropland = c(11088, 11168, 12001, 13091, 16354, 16371, 19713),
Pasture = c(1094, 1234, 1379, 1563, 3797, 3792, 3823),
Forest = c(24623, 24051, 22970, 21633, 20247, 17989, 17742),
Scrubland = c(14774, 15090, 15125, 14883, 10036, 11693, 8266),
No_Vegetation = c(167, 163, 161, 161, 108, 130, 94),
Water = c(844, 844, 844, 844, 844, 844, 844)
)
Create Sankey Diagram
sankey_data <- data[, c("Year", "Urban", "Cropland", "Pasture", "Forest", "Scrubland", "No_Vegetation", "Water")]
Extract unique node names
nodes <- data.frame(name = unique(c(as.character(sankey_data$Year), names(sankey_data)[-1])))
sankey_graph <- sankeyNetwork(
Links = sankey_data,
Nodes = nodes,
Source = "Year",
Target = names(sankey_data)[-1],
units = "TWh",
fontSize = 12,
nodeWidth = 30
)
Display the Sankey Diagram
print(sankey_graph)