Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show edges in Network graph plot in R in different color for different features?

Tags:

graph

r

enter image description here I have made a network graph in R for the transaction between 5 customers and 10 merchants, there are some "Disputed" and some "Undisputed" transcations in it, how can I show these edges corresponding to these to different kind of transactions with different color

like image 862
udAyKumArVermA Avatar asked Dec 04 '25 10:12

udAyKumArVermA


1 Answers

You can pass edge colors into the plot function...

library(igraph)

cust <- c("Jeff", "Jared", "Ronald", "Donald","Barry")
stores <- c("Walmart", "Bestbuy", "McDonalds", "Amazon", "Target","Lowes", "Subway","RadioShack", "Macys","TJ Max")
trans <- c("Disputed", "Undisputed")

df <- data.frame(cust=rep(cust, 5), store=sample(stores, 25, replace = T), trans=sample(trans, 25, replace = T, prob=c(0.3, 0.7)))

g <- graph_from_data_frame(df)
plot(g, edge.color=as.character(factor(df$trans,labels = c("Red", "Blue4"))), edge.arrow.size=0, edge.width=2)

enter image description here

like image 189
emilliman5 Avatar answered Dec 07 '25 07:12

emilliman5



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!