使用ndtv为网络设置动画时,我得到了意外的结果。顶点根据对数值进行缩放,但由于我不清楚的原因,未绘制具有较小值的顶点。添加常数以设置最小顶点大小不起作用。这是我的代码:
# load requisite libaries
require(sna)
require(tsna)
require(ndtv)
require(networkDynamic)
require(lubridate)
# read in pre-processed data
nodelist <- read.csv("https://github.com/aterhorst/data/raw/master/nodelist.csv", header=T, stringsAsFactors = F)
edgelist <- read.csv("https://github.com/aterhorst/data/raw/master/edgelist.csv", header=T, stringsAsFactors = F)
nodelist_expanded <- read.csv("https://github.com/aterhorst/data/raw/master/nodelist_expanded.csv", header=T, stringsAsFactors = F)
# colour code nodes
nodelist$col <- ifelse(nodelist$portfolio == T, "red", "blue")
# shape nodes
nodelist$shape <- ifelse(nodelist$portfolio == T, 4, 12)
# convert dates to year
nodelist_expanded$onset <- year(nodelist_expanded$onset)
nodelist_expanded$terminus <- year(nodelist_expanded$terminus)
# aggregate budget data
nodelist_expanded$budget <- nodelist_expanded$appropriation + nodelist_expanded$ext_revenue
# scale budget
nodelist_expanded$log_budget <- log1p(nodelist_expanded$budget) / 10
# convert dates to year
edgelist$onset <- year(edgelist$onset)
edgelist$terminus <- year(edgelist$terminus)
# create basic network object
nw <- network(edgelist[,c(2,3)],
vertex.attr = nodelist[,c(1:5)],
vertex.attrnames = c("vertex.id", "agency", "portfolio", "col", "shape"),
directed = F)
# create dynamic network object
nd <-networkDynamic(nw,
edge.spells = edgelist[,c(4,5,3,2)],
vertex.spells = nodelist_expanded[,c(5,6,1,8)],
create.TEAs = TRUE,
vertex.TEA.names = "log_budget")
reconcile.vertex.activity(nd, mode = "match.to.edges")
# create animation
render.d3movie(nd,
displaylabels = FALSE,
vertex.col = "col",
vertex.sides = "shape",
vertex.rot = 45,
vertex.cex = "log_budget",
# This slice function makes the labels work
vertex.tooltip = function(slice) {paste("<b>Agency:</b>", (slice %v% "agency"))})
这将渲染正确的动画,但某些边缘没有终止节点/顶点。这些缺少的顶点对应于预算非常小的代理商。我该怎么办才能补救?