r - Plot vertices at the same position -



r - Plot vertices at the same position -

is there method plot shared nodes of 2 graphs @ same position? e.g., 2 graphs

g1 = graph.ring(5) v(g1)$name=c('node1','node2','node3','node4','node5') g1 = g1 - v(g1)[1] g2 = graph.ring(5) v(g2)$name=c('node1','node2','node3','node4','node5') g2 = g2 - v(g2)[2]

there 3 nodes same g1 , g2. how can plot them same nodes having same position easy compare difference?

par(mfrow=c(1,2)) plot(g1, vertex.label=v(g1)$name) plot(g2, vertex.label=v(g2)$name)

using code question linked in comments can take positions 1 graph , utilize them on another.

# graphs - tweaked node names g1 = graph.ring(5) v(g1)$name=letters[1:5] g1 = g1 - v(g1)[1] g2 = graph.ring(5) v(g2)$name=letters[2:6] g2 = g2 - v(g2)[2] # graph layouts # g1 set.seed(1) layg1 <- layout.fruchterman.reingold(g1) # g2 set.seed(2) layg2 <- layout.fruchterman.reingold(g2) # overwrite coords shared nodes layg2[which(v(g2)$name %in% v(g1)$name), ] <- layg1[which(v(g1)$name %in% v(g2)$name),] xlim <- range(c(layg1[,1], layg2[,1])) ylim <- range(c(layg1[,2], layg2[,2]))

plot side side

par(mfrow=c(1,2)) plot(g1 , vertex.size=50, layout=layg1, xlim=xlim, ylim=ylim, rescale=false) plot(g2 , vertex.size=50, layout=layg2, xlim=xlim, ylim=ylim, rescale=false)

or else colour 1 set of nodes , edges

v(g2)$color <- "red" e(g2)$color <- "red" plot(g1 , vertex.size=50, layout=layg1, xlim=xlim, ylim=ylim, rescale=false) plot(g2 , vertex.size=30, layout=layg2, xlim=xlim, ylim=ylim, rescale=false, add=t)

r plot position igraph

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -