i want to make sankey graph can you make beauty sankey graph using this data i want to show landuse changes from 1900 to 2019

library(dplyr)
library(tidyr)
library(networkD3)

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)
)

links <-
data %>%
pivot_longer(-Year) %>%
unite("source", Year, name, remove = FALSE) %>%
mutate(target = lead(source, order_by = Year), .by = name) %>%
filter(!is.na(target))

nodes <- data.frame(name = unique(c(links$source, links$target)))
nodes$group <- sub("[1]{4}_", "", nodes$name)

links$source <- match(links$source, nodes$name) - 1
links$target <- match(links$target, nodes$name) - 1

sankeyNetwork(
Links = links,
Nodes = nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "name",
NodeGroup = "group"
)


  1. 0-9 ↩︎

seems like you made it ...

no this sankey created by poist community member

ok, 'seems like you have it'

What do you want to know from us ?

`i want to shows some changes year by year from 1900 to 2019 i have a dataset which show the yearwise landuse changes . there should be seven column which show the year and rows should be shown landuse types .each year contain seven categories we want to show the changes of sri lanka landuse .

What have you tried so far? what is your specific problem?, we are more inclined towards helping you with specific coding problems rather than doing your work for you.

You have provided working code, which is an example of generate sankey network from example data.
you seem to be asking us to adapt the code to work on data you have, that you havent shared. This is unreasonable.

You could perhaps provide a REPRoducible EXample (reprex) where the data is a reasonable sample of yours, given that that seems to be the point of difficulry for you.

A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.