SankeyNetwork...如何处理添加的数据
SankeyNetwork... How to deal with added Data
这是物种分类的(完全随机的)图表示例:
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)
但是,颜色无法正确匹配,我不知道如何正确设置它们...我想要的是“新”和“绝种”具有独特的颜色,而其他颜色则具有将颜色与相应的类别相匹配。
有任何想法吗?
也许是一个不同的绘图软件允许我添加这个类别或者只是 2 个堆叠条和它们之间的流,所有这些 Sankey-Network-Stuff 似乎对我想要的东西投入过度......
我尝试更明确地说明颜色(即列出所有节点)
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" ])'
在这种情况下,只有“new 2021”是正确的,“unknown”是深灰色,其他的都是黑色。
您答案中的颜色编码似乎无法识别,因此 returns 黑色。您可以使用 RGB 颜色编码来解决问题。我不完全确定为什么无法识别这些颜色。 sankeyNetwork 函数可能不支持它。请查看此功能的文档以获取更多信息。
### set colors --> Change colours to RGB codes. e.g. Olivegreen2 = #a2cd5a
my_color <- 'd3.scaleOrdinal()
.domain(["new2021","casual","established_local","established","unknown","questionable","casual","established_local","established","unknown", "questionable","extinct"])
.range(["red","#a2cd5a","darkolivegreen3","darkolivegreen4","darkgrey","gold3","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)
这是物种分类的(完全随机的)图表示例:
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)
但是,颜色无法正确匹配,我不知道如何正确设置它们...我想要的是“新”和“绝种”具有独特的颜色,而其他颜色则具有将颜色与相应的类别相匹配。 有任何想法吗? 也许是一个不同的绘图软件允许我添加这个类别或者只是 2 个堆叠条和它们之间的流,所有这些 Sankey-Network-Stuff 似乎对我想要的东西投入过度......
我尝试更明确地说明颜色(即列出所有节点)
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" ])'
在这种情况下,只有“new 2021”是正确的,“unknown”是深灰色,其他的都是黑色。
您答案中的颜色编码似乎无法识别,因此 returns 黑色。您可以使用 RGB 颜色编码来解决问题。我不完全确定为什么无法识别这些颜色。 sankeyNetwork 函数可能不支持它。请查看此功能的文档以获取更多信息。
### set colors --> Change colours to RGB codes. e.g. Olivegreen2 = #a2cd5a
my_color <- 'd3.scaleOrdinal()
.domain(["new2021","casual","established_local","established","unknown","questionable","casual","established_local","established","unknown", "questionable","extinct"])
.range(["red","#a2cd5a","darkolivegreen3","darkolivegreen4","darkgrey","gold3","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)