1

I have a data frame with two columns(edgelist)and I want to color the two columns in two different colors in the igraph plots. Like the capital letter node in blue and the small letter in dark read. My code is below.

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))

Thanks!

adR
  • 305
  • 4
  • 14

1 Answers1

1

You can call out the graph element and assign the color based on the condition of whether the value is upper/lower case.

V(g)$color <- ifelse(V(g)$name==toupper(V(g)$name),"blue","red")

Try plotting the graph after this line

Ashish
  • 337
  • 3
  • 11