I would like to use igraph to explore some network data. My data have this structure:
a <- c(13, 32, NA, NA)
b <- c(32, NA, NA, NA)
c <- c(34, 13, 32, NA)
d <- c(5, NA, NA, NA)
net <- rbind(a, b, c, d)
First column: focal subject id From 2 to 4 columns: receivers from focal subject
In the plot, subject 5 should be isolated.
library(reshape)
library(igraph)
net <- as.data.frame(net)
mdata <- melt(net, id=c("V1"))
g <- graph.data.frame(mdata[,c(1,3)])
Warning message:
In graph.data.frame(mdata[, c(1, 3)]) :
In `d' `NA' elements were replaced with string "NA"
plot(g)
As expected, NA appears as a node. Any ideas on how to deal with this?
I had to define vertices and edges separately:
v <- unique(net[, 1])
mdata <- melt(net, id=c("V1"))
e <- na.omit(mdata[,c(1,3)])
g <- graph.data.frame(e, vertices=v, directed=TRUE)
plot(g)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.