2

I'm trying to color only self-loop edges in my igraph network. Here is the sample of my data.

head(network.txt)
From    To
A   A
A   B
A   C
A   D
B   A
B   B
B   C
B   D
C   A
C   B
C   C
C   D
D   A
D   B
D   C
D   D 

Here is the network code

df=read.table("network.txt", header = TRUE)

nodes=unique(df$From)

g=graph_from_data_frame(df)

plot(g, edge.arrow.size=0.2, vertex.color="gold", vertex.size=15, vertex.frame.color="gray", vertex.label.color="black", vertex.label.cex
     =0.5, vertex.label.dist=0, edge.curved=0.2, edge.color="black", main="Adult CRC network", layout=layout_in_circle)

and

> head(E(g))
+ 6/16 edges from ea19d0a (vertex names):
[1] A->A A->B A->C A->D B->A B->B

Here is the output network

Also, is there anyway to keep the loops outside of the network?

user1676
  • 23
  • 3
  • Welcome to Stackoverflow. Please hover over the R tag - it asks for a minimal reproducible example. [Here's a guide](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610) on how to make one. `read.table("network.txt")` is not very helpful to reproduce your problem, as noone except you has got the data. – lukeA Oct 24 '17 at 10:35

1 Answers1

3

You could do it like this:

library(igraph)
g <- make_full_graph(10, loops = TRUE)
plot(g, edge.color = ifelse(is.loop(g), "red", "grey"))

enter image description here

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • Perfect. This is what I need. Thank you. Also is there anyway to keep "self loop" outside of the network. Apologies for not including this in the main thread. – user1676 Oct 24 '17 at 10:36
  • @user1676 I dunno. I guess you can play arround with `loop.angle` - see `?igraph.plotting`. But I don't think so. – lukeA Oct 24 '17 at 10:50
  • AMAIZING! this is the first time that I know R can do this beautiful stuff. –  Oct 24 '17 at 11:13