5

I have a 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 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 it is not pretty when done on my actual data set as the white edges "cut through" the other edges i.e.

enter image description here

Are there other way of simply controlling which edges are visible whilst showing all the vertices? Thanks

daedalus
  • 10,873
  • 5
  • 50
  • 71
Elizabeth
  • 6,391
  • 17
  • 62
  • 90

1 Answers1

6

I wonder what happens if you set the color of the lines to be transparent, something like:

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

I cooked up that color number with:

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

Alternatively, you could go in and omit them from your edgelist.

Seth
  • 4,745
  • 23
  • 27
  • 1
    This is actually not perfect, because some devices do not support transparency. A better solution is to set the line type to `0`, which means no line at all: `E(df)[ bond.strength < 34 ]$lty <- 0`. – Gabor Csardi Mar 03 '13 at 15:32
  • pretty cool! transparency was the trick I need to make nodes silently disappear. size = 0, shape = "none" and a lot of other settings simply didn't work. thanks – Raffael Mar 17 '13 at 13:09