我一直在尝试使用GoogleVis更改R中的sankey图的颜色,this question是最接近我的需求。
以下是数据:
datSK <- data.frame(From=c(rep("A",3), rep("B", 3), rep(c("X", "Y", "Z"), 2 )),
To=c(rep(c("X", "Y", "Z"),2), rep("M", 3), rep("N", 3)),
Weight=c(5,7,6,2,9,4,3,4,5,6, 4,8))
colors_link <- c('green', 'blue', 'yellow', 'brown', 'red')
colors_link_array <- paste0("[", paste0("'", colors_link,"'", collapse = ','), "]")
colors_node <- c('yellow', 'lightblue', 'red', 'black', 'brown', 'green', 'brown')
colors_node_array <- paste0("[", paste0("'", colors_node,"'", collapse = ','), "]")
opts <- paste0("{
link: { colorMode: 'source',
colors: ", colors_link_array ," },
node: { colors: ", colors_node_array ," }
}" )
plot( gvisSankey(datSK, from="From", to="To", weight="Weight",
options=list(
sankey=opts)))
例如,如果您想更改三个绿色怎么办?你自找的 A-> X为绿色 但A-> Y&A-> Z为紫色?代码将如何更改?