Если я использую большую выборку вашего фрейма данных, график работает для меня ...
library(tidyverse)
library(networkD3)
forced_network_df <- read_csv('
"ID", "to", "from", "IndustryID1", "IndustryID2", "Industry1", "Industry2", "value"
1, 1, 1, 3162, 1133, "Footwear manufacturing", "Logging", 7
2, 1, 2, 3162, 55, "Footwear manufacturing", "Management of companies & enterprises", 8
3, 1, 3, 3162, 928110P7, "Footwear manufacturing", "Military Reserves or National Guard", 6
4, 1, 4, 3162, 3114, "Footwear manufacturing", "Fruit & vegetable preserving & specialty food manufacturing", 6
5, 1, 5, 3162, 54194, "Footwear manufacturing", "Veterinary services", 6
6, 2, 6, 311M2, 5419Z, "Seafood & other miscellaneous foods, n.e.c.", "Other professional, scientific & technical services", 7
7, 2, 7, 311M2, 311S, "Seafood & other miscellaneous foods, n.e.c.", "Not specified food industries, manufacturing", 6
8, 2, 8, 311M2, 3118Z, "Seafood & other miscellaneous foods, n.e.c.", "Bakeries & tortilla manufacturing, except retail bakeries", 6
')
edge <- forced_network_df %>% select(from, to, value) %>% mutate(from=from-1, to=to-1)
node <- forced_network_df %>% select(ID, Industry1) %>% mutate(ID = ID-1)
forceNetwork(Links = edge, Nodes = node, Source = "from", Target = "to",
NodeID = "Industry1", Group = "ID", Value = "value", opacity = 1,
width = 550, height = 100, zoom = TRUE)
Если я использую образецedge
и node
фреймов данных, которыми вы поделились, график не отображается ...
library(tidyverse)
library(networkD3)
edge <- tribble(
~from, ~to, ~value,
0, 0, 7,
1, 0, 8,
2, 0, 6,
3, 0, 6,
4, 0, 6,
5, 1, 7,
6, 1, 6
)
node <- tribble(
~ID, ~Industry1,
0, "Footwear manufacturing",
1, "Footwear manufacturing",
2, "Footwear manufacturing",
3, "Footwear manufacturing",
4, "Footwear manufacturing",
5, "Seafood & other miscellaneous foods, n.e.c."
)
forceNetwork(Links = edge, Nodes = node, Source = "from", Target = "to",
NodeID = "Industry1", Group = "ID", Value = "value",
opacity = 1, width = 550, height = 100,
zoom = TRUE)
Это потому, что вы указали 7 различных узлов в вашем edge
фрейме данных (0-6), но у вас есть только 6 узлов в вашем node
кадре данных. Вы можете легко проверить это с ...
any(c(edge$from, edge$to) + 1 > nrow(node))
#[1] TRUE