networkd3包包含一些非常好的函数,用于创建明显的网络。不同的函数有不同的参数,所以这个问题专门针对radialNetwork() 函数。是否可以根据给定的向量使节点笔划的颜色发生变化?
下面的代码创建了一个网络图,但将节点笔划的参数更改为包含不同颜色的向量不起作用。
library(networkD3)
library(tidyverse)
library(data.tree)
## Data
input <- list(number=50)
Data_tree <- data.frame(Start="Class",
Asset = sample(c("FI","Equity","Currency","Commodities"),input$number,replace = TRUE),
Sub_Asset = sample(c("Asia","Europe","USA","Africa","ME"),input$number,replace = TRUE),
Ticker = replicate(input$number,paste0(sample(LETTERS,3),collapse=""))) %>%
unite(col="pathString",Start,Asset,Sub_Asset,Ticker,sep="-",remove=FALSE) %>%
select(-Start) %>% as.Node(pathDelimiter = "-")
radialNetwork(ToListExplicit(Data_tree, unname = TRUE ),
linkColour = "#ccc",
nodeColour = "#fff",
nodeStroke = "orange",
textColour = "#cccccc")