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