我有一个相对较大的数据集,我将其转换为静态网络,然后转换为动态网络,并最终使用render.d3movie()创建了ndtv动画。在动画中,我希望连接不同节点的边缘显示属性,而我为此而苦苦挣扎。
以下是我尝试做的一个虚构示例:
library(networkDynamic)
library(ndtv)
library(network)
Origin <- c("New Zealand", "Canada", "Japan", "China","New Zealand", "Germany", "Spain", "Ghana", "China", "Brazil")
Destination <- c("Canada", "Brazil", "Italy", "Thailand", "Australia", "Spain", "Spain", "Ghana", "Cambodia", "Spain")
Years <- c("2015", "2015", "2015", "2015", "2016", "2016", "2016", "2017", "2017", "2017")
Flights <- as.numeric(c("100", "105", "201", "100", "202", "203", "98", "109", "130", "125"))
DF <- cbind.data.frame(Origin, Destination, Years, Flights)
Flight.List <- split(DF, Years)
#Static networks for each year:
Flights <- lapply (Flight.List, function (x) as.numeric(x$Flights))
Networks <- lapply(Flight.List, function (x) {as.network (x,
matrix.type="edgelist",directed=T, loops= FALSE)})
Networks <- mapply (function (n, m) {set.edge.attribute (n,
"Flights", m)}, Networks, Flights, SIMPLIFY=FALSE)
#Dynamic network:
Dynamic.Network <- networkDynamic(network.list=Networks, vertex.pid="vertex.names",create.TEAs=TRUE)
#Animation
render.d3movie(Dynamic.Network,displaylabels=TRUE, edge.tooltip = paste(Dynamic.Network %e% "Flights.active"))
我希望能够单击节点之间的每个边缘,并查看该特定年份那两个国家之间有多少航班。目前,有些标签是正确的,但大多数标签已关闭。我觉得这可能是因为动画不知道如何分割“ Flights.active”属性。所以我尝试了以下方法:
render.d3movie(Dynamic.Network,displaylabels=TRUE, edge.tooltip = function(slice) {paste(slice %e% "Flights.active", "flights")})
这也不成功-可能是因为我需要在某个时候定义“切片”,但我不知道该怎么做。如果我在动态网络中折叠个别年份,那么那里的属性似乎是正确的。
任何帮助将不胜感激。