Here is an example of a (totally random) graph of a categorization of species:
stat.old<-c("new2021","casual_old","established_local_old","established_old","unknown_old","questionable_old")
stat.new<-c("casual","established_local","established","unknown","questionable", "extinct")
dummytest<-expand.grid(stat.old=stat.old,stat.new=stat.new)
### value defines how MANY species are in this specific "flow"
dummytest$value<-sample(c(0:50),36,replace=T)
dummynodes<-data.frame(name=c(as.character(dummytest$stat.old), as.character(dummytest$stat.new)) %>%
unique())
### use match() to find IDs for the nodes
dummytest$idsource<-match(dummytest$stat.old, dummynodes$name)-1
dummytest$idtarget<-match(dummytest$stat.new, dummynodes$name)-1
### then gsub the "_old" out, so that the nodes have the same name
dummynodes$name<-gsub("_old","", dummynodes$name)
### set colors
my_color <- 'd3.scaleOrdinal() .domain(["new2021","casual","established_local","established","unknown","questionable", "extinct"]) .range(["red","darkolivegreen2","darkolivegreen3","darkolivegreen4","gold3","darkgrey", "black ])'
### plot network
sankeyNetwork(Links=dummytest, Nodes=dummynodes, Source="idsource",Target="idtarget", Value="value", NodeID="name", sinksRight=F, fontSize=22, fontFamily="Calibri", colourScale=my_color)
However, the colors just won't match up properly and I have no idea how to set them properly... what I want is "new" and "extinct" to have a distinct color and the others to have matching colors to their corresponding categories. Any ideas? Maybe a different plotting software that allows me to add this category or just 2 stacked bars with the flows between them, all this Sankey-Network-Stuff seems overly invested for what I want...
I have tried being more explicit about the colors (i.e. listing all nodes)
my_color <- 'd3.scaleOrdinal()
.domain(["new2021","casual","established_local","established","unknown","questionable","casual","established_local","established","unknown", "questionable","extinct"])
.range(["red","darkolivegreen2","darkolivegreen3","darkolivegreen4","darkgrey","gold3","darkolivegreen2","darkolivegreen3","darkolivegreen4","gold3", "darkgrey","black" ])'
In this case only "new 2021" turns up correct, "unknown" is darkgrey and all others turn out black.