networking - How to fix nodes when plotting a subset over a complete network using igraph R -



networking - How to fix nodes when plotting a subset over a complete network using igraph R -

i have problem concerning network visualization using igraph bundle provided in r.

assume have network, contains total sample of nodes , edges. allow me name network netx:

netx <- structure(c(1, 0.48275862, 0.51724138, 0.48275862, 0.27906977, 0.06896552, 0.34482759, 0.32352941, 0.06896552, 0.34482759, 0.03448276, 0.06896552, 0.20689655, 0.17241379, 0.17241379, 0, 0.23333333, 0.27586207, 0.21621622, 0.24137931, 0.48275862, 1, 0.4137931, 0.35714286, 0.25581395, 0.25, 0.25, 0.38235294, 0.07142857, 0.28571429, 0.21428571, 0.28571429, 0.10714286, 0.07142857, 0.21428571, 0.03571429, 0.2, 0.32142857, 0.16216216, 0.25, 0.51724138, 0.4137931, 1, 0.5862069, 0.34883721, 0.06896552, 0.20689655, 0.32352941, 0, 0.27586207, 0.10344828, 0.06896552, 0.10344828, 0.10344828, 0.13793103, 0, 0.36666667, 0.24137931, 0.21621622, 0.17241379, 0.48275862, 0.35714286, 0.5862069, 1, 0.23255814, 0.11538462, 0.23076923, 0.26470588, 0, 0.30769231, 0.11538462, 0.07692308, 0.11538462, 0.15384615, 0.25, 0.03846154, 0.26666667, 0.21428571, 0.21621622, 0.14285714, 0.27906977, 0.25581395, 0.34883721, 0.23255814, 1, 0.18604651, 0.11627907, 0.18604651, 0, 0.18604651, 0.25581395, 0.25581395, 0.27906977, 0.13953488, 0.20930233, 0.04651163, 0.23255814, 0.34883721, 0.25581395, 0.30232558, 0.06896552, 0.25, 0.06896552, 0.11538462, 0.18604651, 1, 0.13043478, 0.32352941, 0, 0.25, 0.34782609, 0.34782609, 0.16666667, 0.13043478, 0.35714286, 0.17391304, 0.16666667, 0.28571429, 0.16216216, 0.35714286, 0.34482759, 0.25, 0.20689655, 0.23076923, 0.11627907, 0.13043478, 1, 0.23529412, 0, 0.29166667, 0.04347826, 0.09090909, 0.16666667, 0.33333333, 0.21428571, 0.06666667, 0.23333333, 0.17857143, 0.16216216, 0.21428571, 0.32352941, 0.38235294, 0.32352941, 0.26470588, 0.18604651, 0.32352941, 0.23529412, 1, 0.08823529, 0.29411765, 0.23529412, 0.17647059, 0.11764706, 0.14705882, 0.26470588, 0.08823529, 0.26470588, 0.26470588, 0.32432432, 0.23529412, 0.06896552, 0.07142857, 0, 0, 0, 0, 0, 0.08823529, 1, 0.04166667, 0, 0, 0, 0, 0.03571429, 0, 0, 0, 0.05405405, 0.03571429, 0.34482759, 0.28571429, 0.27586207, 0.30769231, 0.18604651, 0.25, 0.29166667, 0.29411765, 0.04166667, 1, 0.25, 0.25, 0.20833333, 0.125, 0.25, 0.04166667, 0.23333333, 0.17857143, 0.16216216, 0.14285714, 0.03448276, 0.21428571, 0.10344828, 0.11538462, 0.25581395, 0.34782609, 0.04347826, 0.23529412, 0, 0.25, 1, 0.69565217, 0.125, 0.08695652, 0.17857143, 0, 0.16666667, 0.32142857, 0.24324324, 0.25, 0.06896552, 0.28571429, 0.06896552, 0.07692308, 0.25581395, 0.34782609, 0.09090909, 0.17647059, 0, 0.25, 0.69565217, 1, 0.08333333, 0.09090909, 0.17857143, 0, 0.2, 0.35714286, 0.18918919, 0.25, 0.20689655, 0.10714286, 0.10344828, 0.11538462, 0.27906977, 0.16666667, 0.16666667, 0.11764706, 0, 0.20833333, 0.125, 0.08333333, 1, 0.20833333, 0.25, 0.04166667, 0.2, 0.17857143, 0.27027027, 0.28571429, 0.17241379, 0.07142857, 0.10344828, 0.15384615, 0.13953488, 0.13043478, 0.33333333, 0.14705882, 0, 0.125, 0.08695652, 0.09090909, 0.20833333, 1, 0.21428571, 0.15384615, 0.2, 0.25, 0.16216216, 0.14285714, 0.17241379, 0.21428571, 0.13793103, 0.25, 0.20930233, 0.35714286, 0.21428571, 0.26470588, 0.03571429, 0.25, 0.17857143, 0.17857143, 0.25, 0.21428571, 1, 0.10714286, 0.26666667, 0.32142857, 0.37837838, 0.46428571, 0, 0.03571429, 0, 0.03846154, 0.04651163, 0.17391304, 0.06666667, 0.08823529, 0, 0.04166667, 0, 0, 0.04166667, 0.15384615, 0.10714286, 1, 0.16666667, 0.10714286, 0.05405405, 0.07142857, 0.2333333, 0.2, 0.3666667, 0.2666667, 0.2325581, 0.1666667, 0.2333333, 0.2647059, 0, 0.2333333, 0.1666667, 0.2, 0.2, 0.2, 0.2666667, 0.1666667, 1, 0.4, 0.2972973, 0.3, 0.2758621, 0.3214286, 0.2413793, 0.2142857, 0.3488372, 0.2857143, 0.1785714, 0.2647059, 0, 0.1785714, 0.3214286, 0.3571429, 0.1785714, 0.25, 0.3214286, 0.1071429, 0.4, 1, 0.1891892, 0.4285714, 0.21621622, 0.16216216, 0.21621622, 0.21621622, 0.25581395, 0.16216216, 0.16216216, 0.32432432, 0.05405405, 0.16216216, 0.24324324, 0.18918919, 0.27027027, 0.16216216, 0.37837838, 0.05405405, 0.2972973, 0.18918919, 1, 0.43243243, 0.24137931, 0.25, 0.17241379, 0.14285714, 0.30232558, 0.35714286, 0.21428571, 0.23529412, 0.03571429, 0.14285714, 0.25, 0.25, 0.28571429, 0.14285714, 0.46428571, 0.07142857, 0.3, 0.42857143, 0.43243243, 1), .dim = c(20l, 20l), .dimnames = list( c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"), c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t")))

assume farther have subset of network, phone call nety:

sub_netx <- c("a", "d", "h", "l", "o") nety <- netx[sub_netx,sub_netx] nety d h l o 1.00000000 0.48275862 0.3235294 0.06896552 0.1724138 d 0.48275862 1.00000000 0.2647059 0.07692308 0.2500000 h 0.32352941 0.26470588 1.0000000 0.17647059 0.2647059 l 0.06896552 0.07692308 0.1764706 1.00000000 0.1785714 o 0.17241379 0.25000000 0.2647059 0.17857143 1.0000000

my target overlay both networks, 1 can see finish network netx in background , subset nety in forground. first of need load igraph package, determine layout of potential plot , store x , y coordinates.

library(igraph) inetx <- graph.adjacency(netx, mode = "undirected", weighted = true, diag=f) inety <- graph.adjacency(nety, mode = "undirected", weighted = true, diag=f) lay <- layout.fruchterman.reingold(inetx) v(inetx)$x <- lay[, 1] v(inetx)$y <- lay[, 2]

furthermore think not neccessary index of subset, can handy indexing later:

idx <- which(v(inetx)$name %in% c("a", "d", "h", "l", "o"))

we can store node colors upfront:

v(inetx)$color <- "grey" v(inety)$color <- "red"

but happening when seek overlay both networks in simple plot nodes of subset inety not displayed @ position of same nodes of inetx, despite fixed coordinates.

plot.igraph(inetx, layout = lay, vertex.size = 7) plot.igraph(inety, layout = lay[idx,], vertex.size = 4, add together = true)

i can't upload images, reputation low, hope can follow steps on machines.

my question is, why happen? doing wrong in sense of how can prepare node coordinates when overlay 2 networks?

thank much in advance!

the reason igraph plotting functions rescale layout [-1,1] x [-1,1] default. can utilize rescale=false argument plot() , no rescaling performed.

note in case you'll need set limits of plot hand, setting xlim , ylim:

xlim <- range(lay[,1]) ylim <- range(lay[,2]) plot.igraph(inetx, layout = lay, vertex.size = 20, xlim = xlim, ylim = ylim, rescale = false) plot.igraph(inety, layout = lay[idx,], vertex.size = 14, add together = true, rescale = false)

r networking overlay visualization 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 -