Open thebioengineer opened 4 years ago
hi! and yes, there is a reason. we do lots of network animations in our HIV modeling, using the tergm and ndtv packages (examples in the tutorials here: https://statnet.github.io/Workshops/tergm_tutorial.html, https://statnet.github.io/Workshops/ndtv_workshop.html). so the tools are not the issue.
in the Covid case, we don't have data on all the parameters we would need to support a useful animation. for example, duration of ties and time between repeats. also, our nodes are households not individuals. so they don't move around, they stay in a fixed place. we could just animate the ties, but that ends up looking klunky, because you can't optimize node position to minimize tie crossing.
not to mention all of the epi parameters you would need to show transmission (and that would be the next thing people would want to see!).
that said, we are trying to think about how to do this for the next iteration. feel free to fork the repo and suggest, if you're so inclined.
Oh wow, interesting!!
Sorry, I was thinking along the lines of these sorts of plots for converting the static plots you had already created into d3 plots. I was able to do it to them with the code below, so rather than using plot(net.essl, vertex.cex=1.5, vertex.col=3essl, edge.col="gray20")
, I did make_D3_network(net.essl,charge = -1, group = essl)
.
Since you were outputting an HTML document, I was thinking a D3 where people could mouse over and highlight might be interesting.
make_D3_network <- function(network, charge = -30,..., group = 1){
connected_nodes <-
do.call('rbind', lapply(network$mel, function(x)
data.frame(x)))
node_names <-
do.call('rbind', lapply(network$val, function(x)
data.frame(x)))$vertex.names
if(!is.null(connected_nodes)){
links <-
data.frame(
source = connected_nodes[[2]],
target = connected_nodes[[1]],
value = 1
)
} else{
links <-
data.frame(
source = node_names,
target = node_names,
value = 0
)
}
nodes <-
data.frame(
name = node_names,
group = group,
size = 1
)
network_ig <- igraph::graph.data.frame(links,nodes,directed = FALSE)
network_ig_data <- networkD3::igraph_to_networkD3(network_ig)
network_ig_data$nodes$group = group
networkD3::forceNetwork(
Links = network_ig_data$links,
Nodes = network_ig_data$nodes,
NodeID = "name",
Group = "group",
Source = "source",
Target = "target",
Value = "value",
zoom = TRUE,
bounded = FALSE,
charge = charge,
opacity = 1, ...
)
}
right. that's exactly where the issue of HH fixed physical location runs smack into lovely network animation.
I have made an initial stab at placing these networks into the article. There are certainly some rough edges that need to be figured out (I am not sure how much computational burden these will place on browsers (especially for the fully connected network).
Here is a link to the webpage (which I may take down at some point) with the modified plots : https://adamselder.github.io/
A very cool visualization tool no matter what!
It does have a bit of a computational burden, so perhaps not all the plots need to/should be converted to these network plots. The movement makes them a little more engaging, and hovering to see the connections is just another way to highlight the connectivity.
Thanks for the consideration and your comments though!
Thanks @thebioengineer and @Shmelder!
I agree these are beautiful. And I do like the ability to let users move the nodes and look around. And interactivity is always a nice draw. My issue is that I'm trying to balance that with simplicity in this case, which I keep getting very positive feedback about. As well as with the need for it to be transportable to many media, including static news articles, And I also worry that the other aspects of the dynamics here will suggest to people that something is changing that isn't really.
The bigger question of dynamics - about having the relations change, and possibly have an actual disease simulation - is going to have to wait for a more advanced version of this learning tool after we get some funding. And it needs to be tightly focused on some specific understanding goal for the subset of the general public who will gain more understanding from greater complexity and realism.
Again., thanks!!
This is a great visualization tool to show how interconnected we are and how even small amounts of "just one friend" can increase the connections so quickly!
Out of curiosity, is there a reason that the plots were generated to be static images as opposed to D3 network plots? This adds another level of playing around with the networks and helps to show all the connections.
Using {networkD3} and {igraph} these same plots can be made into html widgets.