I'm creating ego networks from a graph in iGraph with R, as per the answer that was kindly provided to this question. I then want to export each ego network as a plot in a PDF or image file (preferably PDF).
As there are 788 'ego networks' in the full dataframe I'd like to make the file name of the PDF match the relevant node ID for the network i.e. the 'From' column of the dataframe. Otherwise it's too hard to find the particular network that I want. How can this be done?
Here's a sample of the network
library(igraph) > dput(droplevels(head(df))) structure(list(From = structure(c(5L, 1L, 6L, 4L, 2L, 3L), .Label = c("ADVANCED DIPLOMA OF ACCOUNTING", "ADVANCED DIPLOMA OF CONVEYANCING", "ADVANCED DIPLOMA OF LEADERSHIP AND MANAGEMENT", "ADVANCED DIPLOMA OF NETWORK SECURITY", "ADVANCED DIPLOMA OF POLICING", "ADVANCED DIPLOMA OF VISUAL ARTS"), class = "factor"), To = structure(c(5L, 1L, 6L, 3L, 2L, 4L), .Label = c("DIPLOMA OF ACCOUNTING", "DIPLOMA OF EVENT MANAGEMENT", "DIPLOMA OF INFORMATION TECHNOLOGY NETWORKING", "DIPLOMA OF LEADERSHIP AND MANAGEMENT", "DIPLOMA OF POLICING", "DIPLOMA OF VISUAL ARTS"), class = "factor")), row.names = c(NA, 6L), class = "data.frame")
I then make it a graph, then an ego graph
g <- graph_from_data_frame(df, directed = TRUE, vertices = NULL) z <- make_ego_graph(g)
And use this loop to export each network
jpeg(filename="EgoGraph%03d.jpeg") for (i in 1:length(z)) { plot(z[[i]]) } dev.off()