I have a manually created an igraph as shown below. I have created a vertex attribute labled "rank" of 1 through 4. When the I create the graph I would like the vertexes to be arranged or laid out based on those vertex attributes. So essentially the first 4 vertexes with the "rank" label of "1" would be at the top of the graph, then the single vertex with the "rank" label of "2" would be underneath the 4 vertexes with the "rank" label of "1" and so on. Is there a an argument or method in the layout to dictate location of vertex based on another column?
if (!require(librarian)){
install.packages("librarian")
library(librarian)
}
librarian::shelf(tidyverse, here, igraph)
g <- make_graph(~ Database+"Sierra Nevada":Panama:Brazil:Pennsylvania:Genetics:
"Ecophysiology & Environmental Data":eDNA:AMPs:Microbiome:"Occupancy & Abundance":Outreach:
Modeling:Mucosome,
"Sierra Nevada"+ Genetics:"Ecophysiology & Environmental Data":eDNA:AMPs:Microbiome:
"Occupancy & Abundance":Outreach:Modeling:Mucosome:Database,
Panama+ Genetics:"Ecophysiology & Environmental Data":eDNA:AMPs:Microbiome:
"Occupancy & Abundance":Outreach:Modeling:Mucosome:Database,
Pennsylvania+ Genetics:"Ecophysiology & Environmental Data":eDNA:AMPs:Microbiome:
"Occupancy & Abundance":Outreach:Modeling:Mucosome:Database,
Brazil+ Genetics:"Ecophysiology & Environmental Data":eDNA:AMPs:Microbiome:
"Occupancy & Abundance":Outreach:Modeling:Mucosome:Database,
Genetics+ "Sierra Nevada":Panama:Brazil:Pennsylvania:Database,
"Ecophysiology & Environmental Data"- "Sierra Nevada":Panama:Brazil:Pennsylvania:Database,
eDNA+ "Sierra Nevada":Panama:Brazil:Pennsylvania:Database,
AMPs+ "Sierra Nevada":Panama:Brazil:Pennsylvania:Database,
Microbiome+ "Sierra Nevada":Panama:Brazil:Pennsylvania:Database,
"Occupancy & Abundance"- "Sierra Nevada":Panama:Brazil:Pennsylvania:Database,
Outreach+ "Ecophysiology & Environmental Data":AMPs:Microbiome:Mucosome:Database,
Modeling+ "Sierra Nevada":Panama:Brazil:Pennsylvania:Genetics:
"Ecophysiology & Environmental Data":eDNA:AMPs:Microbiome:"Occupancy & Abundance":
Modeling:Mucosome:Database,
Mucosome+ "Sierra Nevada":Panama:Brazil:Pennsylvania:Database) %>%
reverse_edges() %>%
set_vertex_attr("rank", value = c(2, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 4, 4, 3))
plot.igraph(g,
layout = g$rank ,
main = "Network",
edge.arrow.size = 0.3,
vertex.label.cex = 0.7,
#vertex.shape="none",
edge.curved = T,
vertex.color=as.factor(V(g)$rank))
>Solution :
There are various layout functions that can be used to affect the layout of the plot. layout_with_sugiyama() puts the nodes into different layers:
plot(g,
main = "Network",
edge.arrow.size = 0.3,
vertex.label.cex = 0.7,
edge.curved = TRUE,
vertex.color=as.factor(V(g)$rank),
layout = layout_with_sugiyama(g, layers = V(g)$rank))
I have not managed to avoid the overlap of the nodes in the top layer, however.
