title: Set igraph vertex color based on vertex attribute using RColorBrewer
body: <p>I have a network in <code>iGraph</code> that has multiple vertex attributes that represent various factors.  I want to color the vertices when I plot the graph based on a specific attribute. Similar to how you use <code>color = variable</code> in <code>ggplot</code>. </p>
  
  <p>The parameter <code>vertex.color</code> within <code>plot()</code> can be used to set the vertex color for all vertices within the network or it can accept RGB values and set vertex color for each vertex. </p>
  
  <p>I've seen <code>RColorBrewer</code> as a way to create a pallet, but I'm not sure how to map that back to the vertex attributes. I also don't want to hard code the colors for each attribute value, as I have multiple attributes, each with a different number of levels.</p>
  
  <pre><code>library(igraph)
  library(RColorBrewer)
  
  # create an example network
  g &lt;- make_ring(5)
  
  # assign vertex attributes
  g &lt;- set.vertex.attribute(g, 'group', 1, 'A')
  g &lt;- set.vertex.attribute(g, 'group', 2, 'A')
  g &lt;- set.vertex.attribute(g, 'group', 3, 'B')
  g &lt;- set.vertex.attribute(g, 'group', 4, 'B')
  g &lt;- set.vertex.attribute(g, 'group', 5, 'C')
  
  # create color pallet based on unique values for vertex attribute
  pal &lt;- brewer_pal(length(unique(V(g)$group)), "Dark2")
  
  # plot network
  plot(g, vertex.color = "gray")
  </code></pre>