Zrobiłem diagram sankey za pomocą rCharts. Oto przykład mojego kodu. Dane oparte są na ten adres URL (http://timelyportfolio.github.io/rCharts_d3_sankey/example_build_network_sankey.html)Zmiana koloru węzłów w diagramie Charkeya rCharts w R
library(devtools)
library(rjson)
library(igraph)
devtools::install_github("ramnathv/rCharts")
library(rCharts)
g2 <- graph.tree(40, children=4)
V(g2)$weight = 0
V(g2)[degree(g2,mode="out")==0]$weight <- runif(n=length(V(g2)[degree(g2,mode="out")==0]),min=0,max=100)
E(g2)[to(V(g2)$weight>0)]$weight <- V(g2)[V(g2)$weight>0]$weight
while(max(is.na(E(g2)$weight))) {
df <- get.data.frame(g2)
for (i in 1:nrow(df)) {
x = df[i,]
if(max(df$from==x$to)) {
E(g2)[from(x$from) & to(x$to)]$weight = sum(E(g2)[from(x$to)]$weight)
}
}
}
edgelistWeight <- get.data.frame(g2)
colnames(edgelistWeight) <- c("source","target","value")
edgelistWeight$source <- as.character(edgelistWeight$source)
edgelistWeight$target <- as.character(edgelistWeight$target)
sankeyPlot2 <- rCharts$new()
sankeyPlot2$setLib('http://timelyportfolio.github.io/rCharts_d3_sankey')
sankeyPlot2$set(
data = edgelistWeight,
nodeWidth = 15,
nodePadding = 10,
layout = 32,
width = 960,
height = 500
)
sankeyPlot2
Jest to wynik diagramu Sankey.
W tym przypadku muszę zmienić kolor węzłów. To dlatego, że muszę podświetlić niektóre węzły, takie jak liczba 2 i 7. Tak więc, Rezultatem czego chcę jest numer 2 i 7 mają czerwony kolor, a inne węzły mają ten sam kolor, na przykład szary.
Jak mogę obsłużyć ten problem?
podziękowaniem za twoją pomoc! Mam jeszcze jedno pytanie. Czy mogę ustawić kolory linków za pomocą Twojej metody? – kmangyo
Tak, zobacz moją edycję. PS: Metoda jest w zasadzie z @timelyportfolio - http://stackoverflow.com/questions/25412223/adding-color-to-sankey-diagram-in-rcharts – lukeA
To naprawdę dobrze! Dziękuję bardzo! – kmangyo