colouring nodes of igraph

Hi Dears,
How to add colour to nodes based on column in edge list? I mean I have two columns (col1 and col2) and I want to colour the two columns in two different colour in the plots. Like the capital letter node in blue and the small letter in dark read.
My code is below . Thanks!

dat <- data.frame(col1 = letters[1:20], col2 = LETTERS[1:20])
library(igraph)
g <- graph.edgelist(as.matrix(dat ),directed = T)
set.seed(2021)
plot(g, layout=  layout_nicely(g))

Hi @amare,

You have to add colour information to the node list. Try

library(igraph)

dat <- data.frame(col1 = letters[1:20], 
                  col2 = LETTERS[1:20])

 g <- graph.edgelist(as.matrix(dat ),directed = T)
 
#assign color information
#try head(V(g)) to see the structure of nodes
V(g)$color <- c("red", "blue" )
 
plot(g, layout= layout_nicely(g))

JW

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.