Reputation: 10395
I can't for the life of me figure out how to structure my data for use in ggnetwork.
I have a separate program that can generate structured data in any format i choose. Given that ggnetwork data can be
How can i import these? Let's go one at a time here--
This part i got-- i just create a matrix via code like
data <- matrix(c(1,0,3,0,5,6,1,2,3), nrow=3)
colnames(data)=rownames(data)=LETTERS[1:3]
net <- network(data, matrix.type="adjacency")
Doable. Straightforward.
In the example here i see this code:
n <- network(rgraph(10, tprob = 0.2), directed = FALSE)
n %v% "family" <- sample(letters[1:3], 10, replace = TRUE)
n %v% "importance" <- sample(1:3, 10, replace = TRUE)
I have no idea what the n %v%
does, but i'd like to be able to do a dump of node id, attribute val
and just import that in to my nodes.
Again, in the example i see
e <- network.edgecount(n)
set.edge.attribute(n, "type", sample(letters[24:26], e, replace = TRUE))
set.edge.attribute(n, "day", sample(1:3, e, replace = TRUE))
But i don't know what that means, or how i can add this data via appending it to my adjacency list, since that is already 1-1 data mapping to edges.
How can I make an import for my edges with their vals, and an import for my nodes vals?
Upvotes: 0
Views: 211
Reputation: 1076
Assuming
(1,0,3,0,5,6,1,2,3)
Are your imorted values, you can try this :
imported_values <- c(1,0,3,0,5,6,1,2,3)
data <- matrix(imported_values, nrow=3)
colnames(data)=rownames(data)=LETTERS[1:3]
net <- network(data, matrix.type="adjacency")
net %v% "importance" <- imported_values
ggplot(net, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges() +
geom_nodes(aes(size = importance)) +
theme_blank()
Upvotes: 0