0

I have two data files. One file contains all the date relationship like "A B", which means A has connection with B. I use this relationship to create the network with igraph. The other one has the data which I want to color these nodes in the igraph and of course all of these data exist in the first file. I wrote these codes below but I'm not sure how to color them.

code:

library(igraph)
dat <-read.graph("data.txt", format = "edgelist",  directed = FALSE )
answer <-read.table("color.txt")
plot.igraph(dat,vertex.size =3,vertex.label=NA,layout=layout.regionld(g,circular=T))

For example:

data.txt:

A B

B C

D A

A C

Color.txt

A

B

I want to draw network with line connected between two data in each row in data.txt and also color the data in the color.txt in the network.

I want to know how could I color these data from the answer in the igraph.

Meng Wang
  • 29
  • 5

1 Answers1

1

You can color the nodes that are in Color.txt like this:

library(igraph)
dat <- readLines(n=4)
A B
B C
D A
A C
col <- readLines(n=2)
A
B
g <- make_graph(unlist(strsplit(dat, " ", T)))
plot(g, vertex.color = V(g)$name %in% col)
lukeA
  • 53,097
  • 5
  • 97
  • 100