I am trying to start off with plotting a basic static network using the data below. The data represents a small cluster of an infectious disease outbreak.
PHStaticEdges
tail head
1 2
1 3
1 4
2 5
PHVertexAttributes
vertex.id name Place
1 A House
2 B House
3 C Flight
4 D Work
5 E Flight
When I run this code:
thenetwork <- network(
PHStaticEdges,
vertex.attr = PHVertexAttributes,
vertex.attrnames = c("vertex.id", "name", "place"),
directed = FALSE,
bipartite = FALSE
)
plot(thenetwork)
I get the following error:
Error in if (matrix.type == "edgelist") { :
missing value where TRUE/FALSE needed
Ultimately I would like to create a temporal plot showing branching edges over time, but I need to get the static plot right first! Where am I going wrong?
Maybe your vertex_list had some factor ? The following code work like a charm:
Phedges <- data.frame(from = c(1,1,1,2) , to= c(2,3,4,5) , stringsAsFactors = F)
#don't want factor in the edges-list
phvertex <- data.frame(stringsAsFactors = F,
vertex.id = 1:5,
name = c("A", "B", "C", "D", "E"),
type = c( 'House', 'House', 'Flight', 'Work', 'Flight')
)
#don't want factor in the nodes-list
thenetwork <- network::network(
Phedges,
vertex.attr = phvertex,
vertex.attrnames = c("vertex.id", "name", "type"),
directed = FALSE,
bipartite = FALSE )
# then you plot if you want = the network is ok
plot(thenetwork)
ggraph::ggraph(thenetwork) + ggraph::geom_node_point() + ggraph::geom_edge_link() +
ggplot2::theme_void() # assuming you have these cool packages.
PS: Good luck with networkDynamic::activate.edges
or dynamic-nodes. In my opinion, play with the tidyverse and the edges-list (in order to select data and create several 'slice' of network, compute analysis and keep understanding of different 'temporal-version' of the same data). It is more easy to filtering an edges-list with the tidyverse than filtering these temporal-networks packages.