Conchuir
Conchuir

Reputation: 25

r igraph edge.lty attribute not working as advertised

The line type attribute, lty, does not appear to work when it is set for a subset of edges

I have edited my original example, which was oversimplified. Thanks to G5W for the initial response. The code below captures the problem I am having.

I have a matrix of vertex pairs and I want to set the lyt value to "dotted" (value 2) for the edge between each pair. As you can see the code works for the color property, but not the lyt property

library(igraph)

m = matrix( c(1, 10, 7, 8), nrow=2,ncol=2,byrow = TRUE) 

g <- graph.ring(10)

E(g)$color = "black"
E(g)$lty = 1
E(g)$width = 1

for(j in 1:nrow(m)){
  E(g)[m[j,1] %--% m[j,2]]$color <- "indianred"
  E(g)[m[j,1] %--% m[j,2]]$label <- "x"
  E(g)[m[j,1] %--% m[j,2]]$width <- 3
  E(g)[m[j,1] %--% m[j,2]]$lyt <- 2
}
plot(g)
E(g)$lty

Would you have any idea why the color, width, and label properties are set ok, but not the lyt property?

plot generated by code above

Upvotes: 2

Views: 474

Answers (1)

G5W
G5W

Reputation: 37661

The problem is that if you set just one value like that, the rest of the values are undefined.

g <- graph.ring(10)
E(g)[2]$lty <- 2
E(g)$lty
 [1] NA  2 NA NA NA NA NA NA NA NA

If you want most edges to be the default (type = 1) and just the one to be type = 2, start by setting all of them to 1 and then change the one edge.

E(g)$lty = 1
E(g)[2]$lty <- 2
plot(g)

Ring

Upvotes: 2

Related Questions