这是我的第一个问题; 所以,请温柔.
我有一些数据形式:
library('networkD3')
Relationships<- data.frame(Parent=c("earth","earth","forest","forest","ocean","ocean","ocean","ocean"),
Child=c("ocean","forest","tree","sasquatch","fish","seaweed","mantis shrimp","sea monster"))
> Relationships
Parent Child
1 earth ocean
2 earth forest
3 forest tree
4 forest sasquatch
5 ocean fish
6 ocean seaweed
7 ocean mantis shrimp
8 ocean sea monster
Run Code Online (Sandbox Code Playgroud)
本质上,这是一个可用于制作网络地图的边缘列表:
net <- graph_from_data_frame(d = Relationships,
directed = T)
plot(net)
Run Code Online (Sandbox Code Playgroud)
我想将它转换为可以在diagonalNetwork下面的函数中使用的形式.
Hierarchical_list <- list(name = "earth",
children = list(list(name = "ocean",
children = list(list(name = "mantis shrimp"),
list(name = "fish"),
list(name = "sea monster"),
list(name = "seaweed")
)),
list(name …Run Code Online (Sandbox Code Playgroud)