-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkD3.R
51 lines (30 loc) · 1.22 KB
/
NetworkD3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# NetworkD3
# Les exemples ci-dessous sont intégralement extraits du fichier Readme appartenant au package NetworkD3
# https://github.com/christophergandrud/networkD3
library(devtools)
install_github("christophergandrud/networkD3 ")
library(networkD3)
#####################################
# Create fake data
src <- c("A", "A", "A", "A", "B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
networkData <- data.frame(src, target)
# Plot
simpleNetwork(networkData)
#####################################
# Load data
data(MisLinks)
data(MisNodes)
# Plot
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.7,
colourScale = JS("d3.scaleOrdinal(d3.schemeCategory20);"))
#####################################
URL <- paste0("https://cdn.rawgit.com/christophergandrud/networkD3/",
"master/JSONdata/energy.json")
Energy <- jsonlite::fromJSON(URL)
# Plot
sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
units = "TWh", fontSize = 12, nodeWidth = 30)