How can I create a Sankey plot that indicates a change in land use class by years from a dataframe that shows proportion of area for each land use class.
lu_dt <- structure(list(LU_class = c("Cropland", "Forest", "Grassland",
"Other Land", "Settlement", "Water", "Wetland"), lu2000p = c(27.79,
22.92, 0.78, 0.05, 47.66, 0.34, 0.46), lu2005p = c(27.86, 22.51,
0.78, 0.05, 48, 0.34, 0.46), lu2010p = c(23.29, 17.37, 0.69,
0.03, 57.86, 0.34, 0.42), lu2015p = c(21.36, 16.95, 0.66, 0.03,
60.24, 0.34, 0.42), lu2020p = c(21.07, 16.81, 0.65, 0.03, 60.68,
0.34, 0.41)), row.names = c(NA, -7L), class = c("tbl_df", "tbl",
"data.frame"))
Code I tried but the output is not what I am looking for
library(tidyverse)
library(networkD3)
lu_dt %>%
pivot_longer(cols = 2:6, names_to = "yrs",values_to = "val")%>%
dplyr::select(yrs, LU_class,val)-> lu_dt_l
links <-lu_dt_l%>%
dplyr::select(source=yrs,target=LU_class,value=val)
nodes <- data.frame(name=c(unique(links$source),unique(links$target)))
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",fontSize = 20, nodeWidth = 20,LinkGroup = "source",
NodeGroup = "name")
I want something like the image below from here.