title: Plot ties originally from two different networks in a merged network
body: <p>I want to merge two networks with exactly the same nodes. In the merged network, I want to plot the edges from different original networks in different colors. Below are what I have done using igraph and the problems I encountered:   </p>
  
  <p>I first set names to the two original graphs, and types to the edges. </p>
  
  <pre><code>g1 = set.graph.attribute(g1, "name", “AA”)
  E(g1)$type = “A”
  g2 = set.graph.attribute(g2, "name", “BB”)
  E(g2)$type = “B”
  </code></pre>
  
  <p>Then, I unite the two graphs.</p>
  
  <pre><code>g = graph.union(g1, g2, byname=TRUE)
  </code></pre>
  
  <p>Here I got an error:</p>
  
  <blockquote>
    <p>Error in .igraph.graph.union.or.intersection("R_igraph_union", ..., byname = byname,  : 
      Some graphs are not named</p>
  </blockquote>
  
  <p>In fact, both two original graphs are named. This error here is a bit strange. I go ahead with the following codes instead. Now it works.</p>
  
  <pre><code>g = graph.union(g1, g2, byname="auto")
  </code></pre>
  
  <p>These are some results I got:</p>
  
  <pre><code>E(g1)
  </code></pre>
  
  <blockquote>
    <p>Edge sequence:
    <a href="https://i.stack.imgur.com/mVZUl.jpg" rel="nofollow noreferrer">1</a> 5 -- 1 [2] 6 -- 1 [3] 4 -- 2 [4] 6 -- 5</p>
  </blockquote>
  
  <pre><code>E(g2)
  </code></pre>
  
  <blockquote>
    <p>Edge sequence:
    <a href="https://i.stack.imgur.com/mVZUl.jpg" rel="nofollow noreferrer">1</a> 3 -- 2 [2] 6 -- 2 [3] 5 -- 4 [4] 6 -- 4 [5] 6 -- 5</p>
  </blockquote>
  
  <pre><code>E(g)
  </code></pre>
  
  <blockquote>
    <p>Edge sequence:
    <a href="https://i.stack.imgur.com/mVZUl.jpg" rel="nofollow noreferrer">1</a> 6 -- 5 [2] 6 -- 4 [3] 5 -- 4 [4] 6 -- 2 [5] 4 -- 2 [6] 3 -- 2 [7] 6 -- 1 [8] 5 -- 1</p>
  </blockquote>
  
  <pre><code>E(g1)$type
  </code></pre>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/mVZUl.jpg" rel="nofollow noreferrer">1</a> "A" "A" "A" "A"</p>
  </blockquote>
  
  <pre><code>E(g2)$type
  </code></pre>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/mVZUl.jpg" rel="nofollow noreferrer">1</a> "B" "B" "B" "B" "B"</p>
  </blockquote>
  
  <pre><code>E(g)$type_1
  </code></pre>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/mVZUl.jpg" rel="nofollow noreferrer">1</a> "A" NA  NA  NA  "A" NA  "A" "A"</p>
  </blockquote>
  
  <pre><code>E(g)$type_2
  </code></pre>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/mVZUl.jpg" rel="nofollow noreferrer">1</a> "B" "B" "B" "B" NA  "B" NA  NA</p>
  </blockquote>
  
  <p>I try to plot the edges with type "A" in red, and edges with type "B" in blue, using the following codes.</p>
  
  <pre><code>plot(g, edge.color=ifelse(E(g)$type_1=="A","red","blue"))
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/mVZUl.jpg" alt="enter image description here"></p>
  
  <p>It just plots the edges with type "B". Why it does plot the edges with type "A"? What's wrong with these codes?</p>
  
  <p>I am also curious if there is a way to keep the name of the edge attribute of the united graph as "type". Here it automatic changes the name into "type_1" and "type_2", which are two attributes. If keeping the name, some edges will be with type "A", come will be "B", and some will be both "A" and "B" (such as edge 5 -- 6 in this case). This might make it easier to plot the edges in different colors.</p>
  
  <p>Any help would be appreciated. Thank you in advance!</p>