Reputation: 1
Example data: https://drive.google.com/file/d/1Tn4-jm1XlYocdoVdEZSM1s5d0Iz65DNF/view?usp=sharing
library("ndtv")
example = read.table(
file = "~/m_pr_tr_x24_ts_sam.dat",
sep = " ",
header = F)
head(example)
unique(example$V4)
# select a sim. subj.
subj_0=example[example$V1==0,]
# select a term "pel_benez_rud"
lxcl_subj_0=subj_0[subj_0$V6=="message-related",]
lxcl_subj_0=lxcl_subj_0[lxcl_subj_0$V3=="G02_tr_x24",]
lxcl_subj_0_pelrud=lxcl_subj_0[lxcl_subj_0$V7=="pel_benez_rud",]
lxcl_subj_0_pelrud$V10=as.list(data.frame(matrix(unlist(strsplit(gsub("\\(|\\)", "", lxcl_subj_0_pelrud$V9),",")), ncol = 2, byrow = TRUE))[1])$X1
names(lxcl_subj_0_pelrud)
# df=lxcl_subj_0_pelrud[c(4,7,8,10)]
df=lxcl_subj_0_pelrud[c(4,7,8,10)]
names(df)=c("start","from","to","weight")
df$weight=as.numeric(df$weight)
df=df[df$weight>0.0,]
# vertex-vertex.id corr.
mapping_df <- data.frame(
string_value = unique(c(df$from,df$to)),
int_value = 1:length(unique(c(df$from,df$to)))
)
lookup_table <- setNames(mapping_df$int_value, mapping_df$string_value)
df$end=df$start+1
names(df)
frs=df[,c(2,1,5)]
tos=df[,c(3,1,5)]
names(frs)=c("vertex","start","end")
names(tos)=c("vertex","start","end")
vertexData=unique(rbind(frs,tos))
edgeData=df[,c("from","to","start","end","weight")]
vertexData$vertex_id=NA
vertexData=vertexData %>%
dplyr::mutate(
vertex_id = lookup_table[vertexData$vertex]
)
vertexData=vertexData[order(vertexData$start),]
edgeData$from_vertex_id=NA
edgeData$to_vertex_id=NA
edgeData=edgeData %>%
dplyr::mutate(
from_vertex_id = lookup_table[edgeData$from],
to_vertex_id = lookup_table[edgeData$to]
)
edgeData=edgeData[order(edgeData$start),]
Issue: I set up a dynamic network net
. With vertex.TEA.names="vertex"
, I tried to introduce another attribute to the vertices. This vertex
value contains the actual labels of the vertices I wish to display after rendering.
However, when I run render.d3movie()
, the labels I intended to display (now illustrated based on vertex.tooltip
, you can mouse over nodes and they will show up) does match with the vertex_ids (now illustrated based on displaylabels
).
I have checked the vertex_ids (now the displayed integers), and they are fine. Just that they are not corresponded with the correct vertex
values I made with vertex.TEA.names
(when you mouse over).
net <- networkDynamic(vertex.spells=vertexData[,c(2,3,4,1)],
edge.spells=edgeData[,c(3,4,6,7,5)],
create.TEAs=TRUE,
edge.TEA.names="weight",
vertex.TEA.names="vertex")
render.d3movie(net,displaylabels = T,edge.lwd = (net %e% "weight.active")/10,
vertex.tooltip = paste("<b>Name:</b>", (net %v% "vertex.active")))
I have tried googling. I expect that the added labels may match with the vertex_ids and that I could display the added labels instead of the vertex_ids in integers.
Upvotes: 0
Views: 40
Reputation: 1
Solution
net <- networkDynamic(vertex.spells=vertexData[,c(2,3,4,1)],
edge.spells=edgeData[,c(3,4,6,7,5)],
create.TEAs=TRUE,
edge.TEA.names="weight",
vertex.TEA.names="vertex")
?reconcile.edge.activity
: "When networkDynamic objects are created from real-world data it is often the case that activity information for vertices and edges may not come from the same source and may not match up exactly. Vertices may be inactive when incident edges are active, etc. The reconcile.vertex.activity function modifies the activity of a network's vertices acording to the mode specified"
reconcile.edge.activity(net,mode="match.to.vertices")
For the following, check skyebend
's answer to this question:
render.d3movie(net,displaylabels = T,edge.lwd = function(slice){slice %e% "weight"*10},
label=function(slice){slice %v% "vertex"})
Upvotes: 0