Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adjust igraph Layout based on "Ranked" Vertex Attribute

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))

enter image description here

I have not managed to avoid the overlap of the nodes in the top layer, however.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading