我试图在networkD3包中使用sankeyNetwork()
绘制Sankey图。
sankeyNetwork(Links = Flow_data, Nodes = Nodes_data,
Source = "Source_ID", Target = "Target",
Value = "value", NodeID = "Nodes_name",
width = 1000, height=600, fontsize = 16, nodeWidth = 50,
colourScale = "d3.scale.category20c()")
可视化效果很好,但我想将颜色范围更改为单个范围。有没有可能改变SankeyNetwork的颜色?我只需要一个范围,例如3种颜色,我可以自己设置(不是d3.scale的预定义的colorscales)。
您可以配置:
sankeyNetwork(Links = Flow_data, Nodes = Nodes_data,
Source = "Source_ID", Target = "Target",
Value = "value", NodeID = "Nodes_name",
width = 1000, height=600, fontsize = 16, nodeWidth = 50,
colourScale = "d3.scale.category20c()") <==== Categorical color
新版本:
d3.scale.ordinal().range(["#7d3945","#e0677b", "#244457"])
now works if changed to:
d3.scaleOrdinal().range(["#7d3945","#e0677b", "#244457"])
感谢@Peter Ellis
使用自定义颜色时是否有办法设置透明度?
"# AARRGGBB"似乎行不通
你可以创建一个selectAll("your_class").style("opacity",0.5),看看这个:stackoverflow.com/questions/6042550/…CSS3有一个完全标准化的解决方案:"fill="rgba(124,240,10,0.5)"
有关颜色参考,请查看此处:http://bl.ocks.org/aaizemberg/78bd3dade9593896a59d
和这里:https://github.com/mbostock/d3/wiki/Ordinal-Scales#categorical-colors