Controlling the edges visible on a network diagram in a graph in r

I have the following diagram created in igraph

set.seed(1410)
df<-data.frame(
"site.x"=c(rep("a",4),rep("b",4),rep("c",4),rep("d",4)),
"site.y"=c(rep(c("e","f","g","h"),4)),
"bond.strength"=sample(1:100,16, replace=TRUE))

library(igraph)
df<-graph.data.frame(df)
V(df)$names <- c("a","b","c","d","e","f","g","h")
layOUT<-data.frame(x=c(rep(1,4),rep(2,4)),y=c(4:1,4:1))
E(df)[ bond.strength < 101 ]$color <- "red"
E(df)[ bond.strength < 67 ]$color <- "yellow"
E(df)[ bond.strength < 34 ]$color <- "green"
V(df)$color <- "white"
l<-as.matrix(layOUT)
plot(df,layout=l,vertex.size=10,vertex.label=V(df)$names,
edge.arrow.size=0.01,vertex.label.color = "black")

enter image description here

I want to show all the vertices / nodes, but only the edges, where bond.strength> 34 (i.e. only the red and yellow edges). I can control this by setting bond.strength <34 to white, but this is not very good when we finished my actual dataset, as the white edges “cut through” the other edges, i.e.

enter image description here

Is there any other way to just control which edges are visible, showing all the vertices? Thanks

+5
source share
1 answer

It is interesting what happens if you set the color of the lines to transparent, for example:

E(df)[ bond.strength < 34 ]$color <- "#FF000000"

I prepared this color number with:

 hsv(1,1,1,alpha=0)

Alternatively, you can enter and omit them from your edgelist.

+5
source

All Articles