networkD3简介

简单介绍R语言networkD3一系列网图的使用

力导向图

简单力导向图

1
2
3
4
5
library(networkD3)
src = c(rep("A",4),rep("B",2),rep("C",2),"D")
target = c("B","C","D","J","E","F","G","H","I")
networkData = data.frame(src,target)
simpleNetwork(networkData)

复杂力导向图

1
2
3
4
5
6
7
8
9
10
data("MisLinks")
data("MisNodes")
forceNetwork(Links = MisLinks,
Nodes = MisNodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "name",
Group = "group",
opacity = 0.8)

桑基图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
URL = paste0("https://cdn.rawgit.com/christophergandrud/networkD3/",
"master/JSONdata/energy.json")
Energy = jsonlite::fromJSON(URL)
sankeyNetwork(Links = Energy$links,
Nodes = Energy$nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "name",
units = "TWh",
fontSize = 12,
nodeWidth = 30,
height = 300,
width = 500)

树状图

辐射

1
2
3
4
5
URL = paste0("https://cdn.rawgit.com/christophergandrud/networkD3/",
"master/JSONdata/flare.json")
Flare = jsonlite::fromJSON(URL,simplifyDataFrame = FALSE)
Flare$children = Flare$children[1:3]
radialNetwork(List = Flare,fontSize = 10,opacity = 0.9)

对角

1
diagonalNetwork(List = Flare,fontSize = 10,opacity = 0.9,height = 500)

聚类

1
2
hc = hclust(dist(USArrests), "ave")
dendroNetwork(hc,height = 500)

喂他一颗糖