R igraph: Color Vertices by column content
NickName:Marc Bernier Ask DateTime:2017-06-16T01:57:00

R igraph: Color Vertices by column content

I am using igraph to plot a graph from SQL Server. I am providing as input a 3 column table:

from   to     color
Node1  NodeA  red
Node1  NodeB  green
Node1  NodeC  blue
Node2  NodeD  red
Node2  NodeE  green

My R script looks like this:

require(igraph)
g <- graph.data.frame(graphdf)
V(g)$label.cex <- 2
png(filename = "'+@outputFile+'", height = 3000, width = 3000, res = 100);
plot(g, vertex.label.family = "sans", vertex.size = 5)
dev.off()

The plot's edges will display with the desired colors, but the vertices themselves do not -- ideally, I want the 'to' vertex to be the color indicated in the 'color' column. I don't care about the 'from's color (it can be the default orange).

I've tried adding this (and variations):

V(g)$color <- graphdf[V(g), 3]

before the png line, but that produces what appear to be random vertex colors.

Copyright Notice:Content Author:「Marc Bernier」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/44573972/r-igraph-color-vertices-by-column-content

More about “R igraph: Color Vertices by column content” related questions

R igraph: Color Vertices by column content

I am using igraph to plot a graph from SQL Server. I am providing as input a 3 column table: from to color Node1 NodeA red Node1 NodeB green Node1 NodeC blue Node2 NodeD red Node2 N...

Show Detail

Color vertices in igraph R or C

I have a network file for two groups, A and B, and I am plotting the network in R using igraph, and I would like the vertices to be colored depending on their group. The vertices are orderered, i.e...

Show Detail

Correctly color vertices in R igraph

I am using igraph to color vertices I have two CSV files answers and topology of the graph. Answers: (this tells that players K and N answered correctly) Player Q1_I1 1 k 1 2 l ...

Show Detail

Color bar legend for values on vertices of igraph in R

I am new in R and I am starting to work on graph visualization over there using igraph. The example below create a simple network of 10 vertices and color them according to color values (which in t...

Show Detail

Number of vertices in Igraph in R

I'm fairly new to IGraph in R. I'm doing community detection using IGraph and have already built my communities /clusters using the walktrap technique. Next, within each cluster, I want to count...

Show Detail

Jaccard coefficient of adjacent vertices in igraph R

It is well known that the Jaccard similarity coefficient of two vertices is the number of common neighbors divided by the number of vertices that are neighbors of at least one of the two vertices u...

Show Detail

igraph in R - find all accessible vertices

is there a way to find all accessible vertices of an igraph in R, like the function acc in the graph package? I can only find a function for adjacent vertices in an igraph but not accessible vertic...

Show Detail

igraph group vertices based on community

from my previous question here Creating Variables with Group in R igraph, I want to put the vertices with the same group/color close together in my type of data just like this one https://lists.non...

Show Detail

R igraph rename vertices

Is there a possibility to rename the vertices in an igraph. I want to plot a certain graph multiple times with different notation on the vertices. Given the following igraph az: &gt; az IGRAPH DN-...

Show Detail

How to determine number of vertices per cluster in R with igraph

normaly when I want to determine the number of vertices for a graph I only need to write in my script : library(igraph) vcount('name of your graph') And then I have it. The thing is that I'm tryin...

Show Detail