Re: [R] community finding in a graph and heatplot
Superb. It works. The results loo great. I just tweaked the function a little bit to suit my needs though. I passed merges and vcount separately as fgc$merges and vcount(g). The vcount attribute was not there in fgc object. Also, I removed the last row from the merges matrix before returning as it was adding the very root level undesired by the heatmap.2 function I was using. The final function looks like this: # To generate a complete dendogram from disconnected subgraphs in merges given by fgc complete.dend - function(merges, vcount) { if (nrow(merges) vcount-1) { miss - seq_len(vcount + nrow(merges))[-as.vector(merges)] miss - c(miss, seq_len(length(miss)-2) + vcount+nrow(merges)) miss - matrix(miss, byrow=TRUE, ncol=2) merges - rbind(merges, miss) } storage.mode(merges) - integer merges[-nrow(merges),] # skip last row } Thank you so much Gabor for this custom complete.dend fucntion. I couldn't find it in the regular igraph library (http://igraph.sourceforge.net/doc/R/00Index.html). Best, Fayez From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Monday, June 04, 2012 6:33 PM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org; Caetano-Anolles, Gustavo Subject: Re: [R] community finding in a graph and heatplot On Sun, Jun 3, 2012 at 4:11 PM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Hmm interesting. To come to think of it there could be many disconnected components in the graph and thus there should be a generic way to either mitigate the disconnectedness in the dendrogram or in the original graph. I had no luck in finding such a trick though google search. I then ran the script on minute-scale graphs and have following results: 1) disconnected graph with three modules: *Vertices 9 *Edges 1 2 1 2 3 1 3 1 1 4 5 1 5 6 1 6 4 1 7 8 1 8 9 1 9 7 1 corresponding fgc$merges matrix: [,1] [,2] [1,]10 [2,]29 [3,]76 [4,]8 11 [5,]43 [6,]5 13 2) connected graph by adding links 1-2 and 4-7 in graph 1): *Vertices 9 *Edges 1 2 1 2 3 1 3 1 1 4 5 1 5 6 1 6 4 1 7 8 1 8 9 1 9 7 1 1 4 1 4 7 1 corresponding fgc$merges matrix: [,1] [,2] [1,]21 [2,]09 [3,]87 [4,]6 11 [5,]54 [6,]3 13 [7,] 14 12 [8,] 15 10 There needs to be a generic way to get fgc$merges of the form 2) from 1). Hints please. Well, how do you merge the unconnected components? I guess you could come up with an order based on modularity, or just merge them in arbitrary order. The following is from igraph 0.6, and I haven't tried it on your data, but it might just work. It merges the individual subtrees in arbitrary order. complete.dend - function(comm) { merges - comm$merges if (nrow(merges) comm$vcount-1) { miss - seq_len(comm$vcount + nrow(merges))[-as.vector(merges)] miss - c(miss, seq_len(length(miss)-2) + comm$vcount+nrow(merges)) miss - matrix(miss, byrow=TRUE, ncol=2) merges - rbind(merges, miss) } storage.mode(merges) - integer merges } Best, Gabor [...] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] community finding in a graph and heatplot
On Sun, Jun 3, 2012 at 4:11 PM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Hmm interesting. To come to think of it there could be many disconnected components in the graph and thus there should be a generic way to either mitigate the disconnectedness in the dendrogram or in the original graph. I had no luck in finding such a trick though google search. I then ran the script on minute-scale graphs and have following results: 1) disconnected graph with three modules: *Vertices 9 *Edges 1 2 1 2 3 1 3 1 1 4 5 1 5 6 1 6 4 1 7 8 1 8 9 1 9 7 1 corresponding fgc$merges matrix: [,1] [,2] [1,] 1 0 [2,] 2 9 [3,] 7 6 [4,] 8 11 [5,] 4 3 [6,] 5 13 2) connected graph by adding links 1-2 and 4-7 in graph 1): *Vertices 9 *Edges 1 2 1 2 3 1 3 1 1 4 5 1 5 6 1 6 4 1 7 8 1 8 9 1 9 7 1 1 4 1 4 7 1 corresponding fgc$merges matrix: [,1] [,2] [1,] 2 1 [2,] 0 9 [3,] 8 7 [4,] 6 11 [5,] 5 4 [6,] 3 13 [7,] 14 12 [8,] 15 10 There needs to be a generic way to get fgc$merges of the form 2) from 1). Hints please. Well, how do you merge the unconnected components? I guess you could come up with an order based on modularity, or just merge them in arbitrary order. The following is from igraph 0.6, and I haven't tried it on your data, but it might just work. It merges the individual subtrees in arbitrary order. complete.dend - function(comm) { merges - comm$merges if (nrow(merges) comm$vcount-1) { miss - seq_len(comm$vcount + nrow(merges))[-as.vector(merges)] miss - c(miss, seq_len(length(miss)-2) + comm$vcount+nrow(merges)) miss - matrix(miss, byrow=TRUE, ncol=2) merges - rbind(merges, miss) } storage.mode(merges) - integer merges } Best, Gabor [...] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] community finding in a graph and heatplot
The problem is that your graph is unconnected, it has two components and the as.dendrogram() function in igraph cannot handle that. fastgreedy.community() returns a matrix of merges that is not a complete dendrogram, the final top level merge of the components is missing. A workaround is to modify the result of fastgreedy.community and add the missing row to the merges matrix, before calling as.dendrogram(). G. On Thu, May 31, 2012 at 7:42 PM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Thank you so much Gabor for taking this on. Please find attached a sample scenario with the problem of malfunctioning dendogram by fgc. I hope this helps you narrow down to the solution. Best, Fayez From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Thursday, May 31, 2012 4:23 PM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org Subject: Re: [R] community finding in a graph and heatplot On Thu, May 31, 2012 at 12:08 PM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Thank you so much Gabor for your reply. I had spotted your post earlier and it worked like a charm. Interestingly I have just ran into a trouble with the stament dend - igraph:::as.dendrogram.igraph.walktrap(fc). Apparently the members are empty as when I print(dend) it says 'dendrogram' with 2 branches and members total, at height 93 while the error with using dend with dendrapply remians to be Error in `[[.dendrogram`(X, 2L) : attempt to set an attribute on NULL Any ideas? I would need to see fgc for this. Can you send it to me in private? Or send some self-contained example that generates the same error? Gabor My code looks like this File2Open = paste(FilePath, NetworkFiles\\net\\, NetPrefix, , TPPostfix, .net, sep = ) g - read.graph(File2Open, format=pajek) g - delete.isolates(g) g - simplify(g) fgc - fastgreedy.community(g, modularity=TRUE, weights = E(g)$weight) ModularityIndexfgc - max(fgc$modularity) # fgc modularity ModularityIndexng - modularity(g, membership, weights = E(g)$weight) # newman-girvan modularity dend - igraph:::as.dendrogram.igraph.walktrap(fgc) png(filename = paste(FilePath, Analysis\\Graphs\\EColiStressModuleHeatMap, NetPrefixAbbr, TPPostfix, .png, sep = ), width = 800, height = 800) # heat map is square adjMatrix = get.adjacency(g, attr=weight) DendNodeCounter - 0 # counter for ColorGroupsOrdered ColorGroupsOrdered - rep(red, vcount(g)) dendrapply(dend, colLab) # modifies ColorGroupsOrdered From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Thursday, May 31, 2012 10:45 AM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org Subject: Re: [R] community finding in a graph and heatplot On Tue, May 29, 2012 at 1:16 AM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Hi everyone, I am using the fastgreedy.community function to get the $merges matrix and the $modularity vector. This serves my purpose of testing modularity of my graph. But I am greedy to plot the heat map and dendrrogram based on the $merges dendogram matrix. I know that heatplot does the graphics part but I am not sure if the dendogram generated by the heatplot will match the one given by fastgreedy.community in all cases and that the heat map will represent the same clustering. No, they are different. To plot fast-greedy results as a dendrogram, see this and the follow-ups: http://lists.gnu.org/archive/html/igraph-help/2010-11/msg00059.html Gabor Tell me if my apprehension is incorrect. Otherwise please let me know of any alternatives. Here is the code I am testing so far: # http://igraph.sourceforge.net/doc/R/modularity.html # http://igraph.sourceforge.net/doc/R/fastgreedy.community.html # http://igraph.sourceforge.net/doc/R/graph.constructors.html library(igraph) library(made4) g - graph(c(1,2, 2,3, 3,1, 4,5)-1, , FALSE) print(g) ModuleInfo - fastgreedy.community(g) print(ModuleInfo) heatplot(c(1,2, 2,3, 3,1, 4,5)) Thanks Fayez Grad student UIUC IL, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo
Re: [R] community finding in a graph and heatplot
Hmm interesting. To come to think of it there could be many disconnected components in the graph and thus there should be a generic way to either mitigate the disconnectedness in the dendrogram or in the original graph. I had no luck in finding such a trick though google search. I then ran the script on minute-scale graphs and have following results: 1) disconnected graph with three modules: *Vertices 9 *Edges 1 2 1 2 3 1 3 1 1 4 5 1 5 6 1 6 4 1 7 8 1 8 9 1 9 7 1 corresponding fgc$merges matrix: [,1] [,2] [1,]10 [2,]29 [3,]76 [4,]8 11 [5,]43 [6,]5 13 2) connected graph by adding links 1-2 and 4-7 in graph 1): *Vertices 9 *Edges 1 2 1 2 3 1 3 1 1 4 5 1 5 6 1 6 4 1 7 8 1 8 9 1 9 7 1 1 4 1 4 7 1 corresponding fgc$merges matrix: [,1] [,2] [1,]21 [2,]09 [3,]87 [4,]6 11 [5,]54 [6,]3 13 [7,] 14 12 [8,] 15 10 There needs to be a generic way to get fgc$merges of the form 2) from 1). Hints please. Thank you so much Gabor for your help so far and marvelous job in identifying the problem. Best, Fayez From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Sunday, June 03, 2012 8:56 AM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org; Caetano-Anolles, Gustavo Subject: Re: [R] community finding in a graph and heatplot The problem is that your graph is unconnected, it has two components and the as.dendrogram() function in igraph cannot handle that. fastgreedy.community() returns a matrix of merges that is not a complete dendrogram, the final top level merge of the components is missing. A workaround is to modify the result of fastgreedy.community and add the missing row to the merges matrix, before calling as.dendrogram(). G. On Thu, May 31, 2012 at 7:42 PM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Thank you so much Gabor for taking this on. Please find attached a sample scenario with the problem of malfunctioning dendogram by fgc. I hope this helps you narrow down to the solution. Best, Fayez From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Thursday, May 31, 2012 4:23 PM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org Subject: Re: [R] community finding in a graph and heatplot On Thu, May 31, 2012 at 12:08 PM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Thank you so much Gabor for your reply. I had spotted your post earlier and it worked like a charm. Interestingly I have just ran into a trouble with the stament dend - igraph:::as.dendrogram.igraph.walktrap(fc). Apparently the members are empty as when I print(dend) it says 'dendrogram' with 2 branches and members total, at height 93 while the error with using dend with dendrapply remians to be Error in `[[.dendrogram`(X, 2L) : attempt to set an attribute on NULL Any ideas? I would need to see fgc for this. Can you send it to me in private? Or send some self-contained example that generates the same error? Gabor My code looks like this File2Open = paste(FilePath, NetworkFiles\\net\\, NetPrefix, , TPPostfix, .net, sep = ) g - read.graph(File2Open, format=pajek) g - delete.isolates(g) g - simplify(g) fgc - fastgreedy.community(g, modularity=TRUE, weights = E(g)$weight) ModularityIndexfgc - max(fgc$modularity) # fgc modularity ModularityIndexng - modularity(g, membership, weights = E(g)$weight) # newman-girvan modularity dend - igraph:::as.dendrogram.igraph.walktrap(fgc) png(filename = paste(FilePath, Analysis\\Graphs\\EColiStressModuleHeatMap, NetPrefixAbbr, TPPostfix, .png, sep = ), width = 800, height = 800) # heat map is square adjMatrix = get.adjacency(g, attr=weight) DendNodeCounter - 0 # counter for ColorGroupsOrdered ColorGroupsOrdered - rep(red, vcount(g)) dendrapply(dend, colLab) # modifies ColorGroupsOrdered From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Thursday, May 31, 2012 10:45 AM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org Subject: Re: [R] community finding in a graph and heatplot On Tue, May 29, 2012 at 1:16 AM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Hi everyone, I am using the fastgreedy.community function to get the $merges matrix and the $modularity vector. This serves my purpose of testing modularity of my graph. But I am greedy to plot the heat map and dendrrogram based on the $merges dendogram matrix. I know that heatplot does the graphics part but I am not sure if the dendogram generated by the heatplot will match
Re: [R] community finding in a graph and heatplot
On Tue, May 29, 2012 at 1:16 AM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Hi everyone, I am using the fastgreedy.community function to get the $merges matrix and the $modularity vector. This serves my purpose of testing modularity of my graph. But I am greedy to plot the heat map and dendrrogram based on the $merges dendogram matrix. I know that heatplot does the graphics part but I am not sure if the dendogram generated by the heatplot will match the one given by fastgreedy.community in all cases and that the heat map will represent the same clustering. No, they are different. To plot fast-greedy results as a dendrogram, see this and the follow-ups: http://lists.gnu.org/archive/html/igraph-help/2010-11/msg00059.html Gabor Tell me if my apprehension is incorrect. Otherwise please let me know of any alternatives. Here is the code I am testing so far: # http://igraph.sourceforge.net/doc/R/modularity.html # http://igraph.sourceforge.net/doc/R/fastgreedy.community.html # http://igraph.sourceforge.net/doc/R/graph.constructors.html library(igraph) library(made4) g - graph(c(1,2, 2,3, 3,1, 4,5)-1, , FALSE) print(g) ModuleInfo - fastgreedy.community(g) print(ModuleInfo) heatplot(c(1,2, 2,3, 3,1, 4,5)) Thanks Fayez Grad student UIUC IL, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] community finding in a graph and heatplot
Thank you so much Gabor for your reply. I had spotted your post earlier and it worked like a charm. Interestingly I have just ran into a trouble with the stament dend - igraph:::as.dendrogram.igraph.walktrap(fc). Apparently the members are empty as when I print(dend) it says 'dendrogram' with 2 branches and members total, at height 93 while the error with using dend with dendrapply remians to be Error in `[[.dendrogram`(X, 2L) : attempt to set an attribute on NULL Any ideas? My code looks like this File2Open = paste(FilePath, NetworkFiles\\net\\, NetPrefix, , TPPostfix, .net, sep = ) g - read.graph(File2Open, format=pajek) g - delete.isolates(g) g - simplify(g) fgc - fastgreedy.community(g, modularity=TRUE, weights = E(g)$weight) ModularityIndexfgc - max(fgc$modularity) # fgc modularity ModularityIndexng - modularity(g, membership, weights = E(g)$weight) # newman-girvan modularity dend - igraph:::as.dendrogram.igraph.walktrap(fgc) png(filename = paste(FilePath, Analysis\\Graphs\\EColiStressModuleHeatMap, NetPrefixAbbr, TPPostfix, .png, sep = ), width = 800, height = 800) # heat map is square adjMatrix = get.adjacency(g, attr=weight) DendNodeCounter - 0 # counter for ColorGroupsOrdered ColorGroupsOrdered - rep(red, vcount(g)) dendrapply(dend, colLab) # modifies ColorGroupsOrdered From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Thursday, May 31, 2012 10:45 AM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org Subject: Re: [R] community finding in a graph and heatplot On Tue, May 29, 2012 at 1:16 AM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Hi everyone, I am using the fastgreedy.community function to get the $merges matrix and the $modularity vector. This serves my purpose of testing modularity of my graph. But I am greedy to plot the heat map and dendrrogram based on the $merges dendogram matrix. I know that heatplot does the graphics part but I am not sure if the dendogram generated by the heatplot will match the one given by fastgreedy.community in all cases and that the heat map will represent the same clustering. No, they are different. To plot fast-greedy results as a dendrogram, see this and the follow-ups: http://lists.gnu.org/archive/html/igraph-help/2010-11/msg00059.html Gabor Tell me if my apprehension is incorrect. Otherwise please let me know of any alternatives. Here is the code I am testing so far: # http://igraph.sourceforge.net/doc/R/modularity.html # http://igraph.sourceforge.net/doc/R/fastgreedy.community.html # http://igraph.sourceforge.net/doc/R/graph.constructors.html library(igraph) library(made4) g - graph(c(1,2, 2,3, 3,1, 4,5)-1, , FALSE) print(g) ModuleInfo - fastgreedy.community(g) print(ModuleInfo) heatplot(c(1,2, 2,3, 3,1, 4,5)) Thanks Fayez Grad student UIUC IL, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] community finding in a graph and heatplot
On Thu, May 31, 2012 at 12:08 PM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Thank you so much Gabor for your reply. I had spotted your post earlier and it worked like a charm. Interestingly I have just ran into a trouble with the stament dend - igraph:::as.dendrogram.igraph.walktrap(fc). Apparently the members are empty as when I print(dend) it says 'dendrogram' with 2 branches and members total, at height 93 while the error with using dend with dendrapply remians to be Error in `[[.dendrogram`(X, 2L) : attempt to set an attribute on NULL Any ideas? I would need to see fgc for this. Can you send it to me in private? Or send some self-contained example that generates the same error? Gabor My code looks like this File2Open = paste(FilePath, NetworkFiles\\net\\, NetPrefix, , TPPostfix, .net, sep = ) g - read.graph(File2Open, format=pajek) g - delete.isolates(g) g - simplify(g) fgc - fastgreedy.community(g, modularity=TRUE, weights = E(g)$weight) ModularityIndexfgc - max(fgc$modularity) # fgc modularity ModularityIndexng - modularity(g, membership, weights = E(g)$weight) # newman-girvan modularity dend - igraph:::as.dendrogram.igraph.walktrap(fgc) png(filename = paste(FilePath, Analysis\\Graphs\\EColiStressModuleHeatMap, NetPrefixAbbr, TPPostfix, .png, sep = ), width = 800, height = 800) # heat map is square adjMatrix = get.adjacency(g, attr=weight) DendNodeCounter - 0 # counter for ColorGroupsOrdered ColorGroupsOrdered - rep(red, vcount(g)) dendrapply(dend, colLab) # modifies ColorGroupsOrdered From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Thursday, May 31, 2012 10:45 AM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org Subject: Re: [R] community finding in a graph and heatplot On Tue, May 29, 2012 at 1:16 AM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Hi everyone, I am using the fastgreedy.community function to get the $merges matrix and the $modularity vector. This serves my purpose of testing modularity of my graph. But I am greedy to plot the heat map and dendrrogram based on the $merges dendogram matrix. I know that heatplot does the graphics part but I am not sure if the dendogram generated by the heatplot will match the one given by fastgreedy.community in all cases and that the heat map will represent the same clustering. No, they are different. To plot fast-greedy results as a dendrogram, see this and the follow-ups: http://lists.gnu.org/archive/html/igraph-help/2010-11/msg00059.html Gabor Tell me if my apprehension is incorrect. Otherwise please let me know of any alternatives. Here is the code I am testing so far: # http://igraph.sourceforge.net/doc/R/modularity.html # http://igraph.sourceforge.net/doc/R/fastgreedy.community.html # http://igraph.sourceforge.net/doc/R/graph.constructors.html library(igraph) library(made4) g - graph(c(1,2, 2,3, 3,1, 4,5)-1, , FALSE) print(g) ModuleInfo - fastgreedy.community(g) print(ModuleInfo) heatplot(c(1,2, 2,3, 3,1, 4,5)) Thanks Fayez Grad student UIUC IL, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] community finding in a graph and heatplot
Thank you so much Gabor for taking this on. Please find attached a sample scenario with the problem of malfunctioning dendogram by fgc. I hope this helps you narrow down to the solution. Best, Fayez From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Thursday, May 31, 2012 4:23 PM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org Subject: Re: [R] community finding in a graph and heatplot On Thu, May 31, 2012 at 12:08 PM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Thank you so much Gabor for your reply. I had spotted your post earlier and it worked like a charm. Interestingly I have just ran into a trouble with the stament dend - igraph:::as.dendrogram.igraph.walktrap(fc). Apparently the members are empty as when I print(dend) it says 'dendrogram' with 2 branches and members total, at height 93 while the error with using dend with dendrapply remians to be Error in `[[.dendrogram`(X, 2L) : attempt to set an attribute on NULL Any ideas? I would need to see fgc for this. Can you send it to me in private? Or send some self-contained example that generates the same error? Gabor My code looks like this File2Open = paste(FilePath, NetworkFiles\\net\\, NetPrefix, , TPPostfix, .net, sep = ) g - read.graph(File2Open, format=pajek) g - delete.isolates(g) g - simplify(g) fgc - fastgreedy.community(g, modularity=TRUE, weights = E(g)$weight) ModularityIndexfgc - max(fgc$modularity) # fgc modularity ModularityIndexng - modularity(g, membership, weights = E(g)$weight) # newman-girvan modularity dend - igraph:::as.dendrogram.igraph.walktrap(fgc) png(filename = paste(FilePath, Analysis\\Graphs\\EColiStressModuleHeatMap, NetPrefixAbbr, TPPostfix, .png, sep = ), width = 800, height = 800) # heat map is square adjMatrix = get.adjacency(g, attr=weight) DendNodeCounter - 0 # counter for ColorGroupsOrdered ColorGroupsOrdered - rep(red, vcount(g)) dendrapply(dend, colLab) # modifies ColorGroupsOrdered From: csardi.ga...@gmail.com [csardi.ga...@gmail.com] on behalf of Gábor Csárdi [csa...@rmki.kfki.hu] Sent: Thursday, May 31, 2012 10:45 AM To: Aziz, Muhammad Fayez Cc: r-help@r-project.org Subject: Re: [R] community finding in a graph and heatplot On Tue, May 29, 2012 at 1:16 AM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Hi everyone, I am using the fastgreedy.community function to get the $merges matrix and the $modularity vector. This serves my purpose of testing modularity of my graph. But I am greedy to plot the heat map and dendrrogram based on the $merges dendogram matrix. I know that heatplot does the graphics part but I am not sure if the dendogram generated by the heatplot will match the one given by fastgreedy.community in all cases and that the heat map will represent the same clustering. No, they are different. To plot fast-greedy results as a dendrogram, see this and the follow-ups: http://lists.gnu.org/archive/html/igraph-help/2010-11/msg00059.html Gabor Tell me if my apprehension is incorrect. Otherwise please let me know of any alternatives. Here is the code I am testing so far: # http://igraph.sourceforge.net/doc/R/modularity.html # http://igraph.sourceforge.net/doc/R/fastgreedy.community.html # http://igraph.sourceforge.net/doc/R/graph.constructors.html library(igraph) library(made4) g - graph(c(1,2, 2,3, 3,1, 4,5)-1, , FALSE) print(g) ModuleInfo - fastgreedy.community(g) print(ModuleInfo) heatplot(c(1,2, 2,3, 3,1, 4,5)) Thanks Fayez Grad student UIUC IL, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI attachment: WhyNot.pngattachment: Splendid.png__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] community finding in a graph and heatplot
Hi everyone, I am using the fastgreedy.community function to get the $merges matrix and the $modularity vector. This serves my purpose of testing modularity of my graph. But I am greedy to plot the heat map and dendrrogram based on the $merges dendogram matrix. I know that heatplot does the graphics part but I am not sure if the dendogram generated by the heatplot will match the one given by fastgreedy.community in all cases and that the heat map will represent the same clustering. Tell me if my apprehension is incorrect. Otherwise please let me know of any alternatives. Here is the code I am testing so far: # http://igraph.sourceforge.net/doc/R/modularity.html # http://igraph.sourceforge.net/doc/R/fastgreedy.community.html # http://igraph.sourceforge.net/doc/R/graph.constructors.html library(igraph) library(made4) g - graph(c(1,2, 2,3, 3,1, 4,5)-1, , FALSE) print(g) ModuleInfo - fastgreedy.community(g) print(ModuleInfo) heatplot(c(1,2, 2,3, 3,1, 4,5)) Thanks Fayez Grad student UIUC IL, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.