Creating new graph basing on cluster anylise - R











up vote
0
down vote

favorite












library("network")
library("networkD3")
library("igraph")

df1 <- read.table(text = "src target
cllient1 cllient2
cllient1 cllient4
cllient1 cllient6
cllient2 cllient3
cllient4 cllient1
cllient4 cllient3
cllient5 cllient6
cllient6 cllient5", header = TRUE)

lesmis <- graph_from_data_frame(df1)
wc <- cluster_walktrap(lesmis)
members <- membership(wc)
lesmis <- igraph_to_networkD3(lesmis, group = members)

D3_network_LM <- networkD3::forceNetwork(Links = lesmis$links, Nodes = lesmis$nodes,
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'group',
opacity = 1,zoom = TRUE)
networkD3::saveNetwork(D3_network_LM, "test.html", selfcontained = TRUE)


So close we got a network. After that we create new graph by merging several vertices into one. In our case those vertices that belong to particular community.



lesmis <- graph_from_data_frame(df1)
cg <- contract.vertices(lesmis, members)
ay <- as_long_data_frame(cg)
View(ay)


we got new graph,



from    to
1 2


We may built again new graph where now these nodes are the groups, but their names are 1 and 2, my question is how we can add clients names to this new graph. So that, when hovering , we may get not only the number of the node(group) but also the list of client that belongs to this new node(group).










share|improve this question
























  • I think here graph_from_data_frame(bank) you mean graph_from_data_frame(df1) to make the example work, and the second part imho is not working, having Error in contract.vertices(lesmis, members) : Not a graph object.
    – s_t
    Nov 20 at 15:14










  • Have edited, thank you
    – Maksym Moroz
    Nov 21 at 7:20















up vote
0
down vote

favorite












library("network")
library("networkD3")
library("igraph")

df1 <- read.table(text = "src target
cllient1 cllient2
cllient1 cllient4
cllient1 cllient6
cllient2 cllient3
cllient4 cllient1
cllient4 cllient3
cllient5 cllient6
cllient6 cllient5", header = TRUE)

lesmis <- graph_from_data_frame(df1)
wc <- cluster_walktrap(lesmis)
members <- membership(wc)
lesmis <- igraph_to_networkD3(lesmis, group = members)

D3_network_LM <- networkD3::forceNetwork(Links = lesmis$links, Nodes = lesmis$nodes,
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'group',
opacity = 1,zoom = TRUE)
networkD3::saveNetwork(D3_network_LM, "test.html", selfcontained = TRUE)


So close we got a network. After that we create new graph by merging several vertices into one. In our case those vertices that belong to particular community.



lesmis <- graph_from_data_frame(df1)
cg <- contract.vertices(lesmis, members)
ay <- as_long_data_frame(cg)
View(ay)


we got new graph,



from    to
1 2


We may built again new graph where now these nodes are the groups, but their names are 1 and 2, my question is how we can add clients names to this new graph. So that, when hovering , we may get not only the number of the node(group) but also the list of client that belongs to this new node(group).










share|improve this question
























  • I think here graph_from_data_frame(bank) you mean graph_from_data_frame(df1) to make the example work, and the second part imho is not working, having Error in contract.vertices(lesmis, members) : Not a graph object.
    – s_t
    Nov 20 at 15:14










  • Have edited, thank you
    – Maksym Moroz
    Nov 21 at 7:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite











library("network")
library("networkD3")
library("igraph")

df1 <- read.table(text = "src target
cllient1 cllient2
cllient1 cllient4
cllient1 cllient6
cllient2 cllient3
cllient4 cllient1
cllient4 cllient3
cllient5 cllient6
cllient6 cllient5", header = TRUE)

lesmis <- graph_from_data_frame(df1)
wc <- cluster_walktrap(lesmis)
members <- membership(wc)
lesmis <- igraph_to_networkD3(lesmis, group = members)

D3_network_LM <- networkD3::forceNetwork(Links = lesmis$links, Nodes = lesmis$nodes,
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'group',
opacity = 1,zoom = TRUE)
networkD3::saveNetwork(D3_network_LM, "test.html", selfcontained = TRUE)


So close we got a network. After that we create new graph by merging several vertices into one. In our case those vertices that belong to particular community.



lesmis <- graph_from_data_frame(df1)
cg <- contract.vertices(lesmis, members)
ay <- as_long_data_frame(cg)
View(ay)


we got new graph,



from    to
1 2


We may built again new graph where now these nodes are the groups, but their names are 1 and 2, my question is how we can add clients names to this new graph. So that, when hovering , we may get not only the number of the node(group) but also the list of client that belongs to this new node(group).










share|improve this question















library("network")
library("networkD3")
library("igraph")

df1 <- read.table(text = "src target
cllient1 cllient2
cllient1 cllient4
cllient1 cllient6
cllient2 cllient3
cllient4 cllient1
cllient4 cllient3
cllient5 cllient6
cllient6 cllient5", header = TRUE)

lesmis <- graph_from_data_frame(df1)
wc <- cluster_walktrap(lesmis)
members <- membership(wc)
lesmis <- igraph_to_networkD3(lesmis, group = members)

D3_network_LM <- networkD3::forceNetwork(Links = lesmis$links, Nodes = lesmis$nodes,
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'group',
opacity = 1,zoom = TRUE)
networkD3::saveNetwork(D3_network_LM, "test.html", selfcontained = TRUE)


So close we got a network. After that we create new graph by merging several vertices into one. In our case those vertices that belong to particular community.



lesmis <- graph_from_data_frame(df1)
cg <- contract.vertices(lesmis, members)
ay <- as_long_data_frame(cg)
View(ay)


we got new graph,



from    to
1 2


We may built again new graph where now these nodes are the groups, but their names are 1 and 2, my question is how we can add clients names to this new graph. So that, when hovering , we may get not only the number of the node(group) but also the list of client that belongs to this new node(group).







r igraph htmlwidgets networkd3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 7:14

























asked Nov 20 at 13:44









Maksym Moroz

249




249












  • I think here graph_from_data_frame(bank) you mean graph_from_data_frame(df1) to make the example work, and the second part imho is not working, having Error in contract.vertices(lesmis, members) : Not a graph object.
    – s_t
    Nov 20 at 15:14










  • Have edited, thank you
    – Maksym Moroz
    Nov 21 at 7:20


















  • I think here graph_from_data_frame(bank) you mean graph_from_data_frame(df1) to make the example work, and the second part imho is not working, having Error in contract.vertices(lesmis, members) : Not a graph object.
    – s_t
    Nov 20 at 15:14










  • Have edited, thank you
    – Maksym Moroz
    Nov 21 at 7:20
















I think here graph_from_data_frame(bank) you mean graph_from_data_frame(df1) to make the example work, and the second part imho is not working, having Error in contract.vertices(lesmis, members) : Not a graph object.
– s_t
Nov 20 at 15:14




I think here graph_from_data_frame(bank) you mean graph_from_data_frame(df1) to make the example work, and the second part imho is not working, having Error in contract.vertices(lesmis, members) : Not a graph object.
– s_t
Nov 20 at 15:14












Have edited, thank you
– Maksym Moroz
Nov 21 at 7:20




Have edited, thank you
– Maksym Moroz
Nov 21 at 7:20












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Your example code doesn't work for multiple reasons (I edited it a bit to fix some obvious problems), but I think the following achieves what you're trying to do...



library(network)
library(networkD3)
library(igraph)

df <- read.table(header = TRUE,
text = "src target
cllient1 cllient2
cllient1 cllient4
cllient1 cllient6
cllient2 cllient3
cllient4 cllient1
cllient4 cllient3
cllient5 cllient6
cllient6 cllient5")

df_graph <- graph_from_data_frame(df)

wc <- cluster_walktrap(df_graph)
members <- membership(wc)

df_graph_cntrctd <- contract(df_graph, members, vertex.attr.comb = toString)

df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd)

networkD3::forceNetwork(Links = df_graph_cntrctd_D3$links,
Nodes = df_graph_cntrctd_D3$nodes,
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'name',
opacity = 1, zoom = TRUE)


enter image description here






share|improve this answer





















  • yep, sorry for that silly mistakes.. Your suggestion solves what I was asking about :) Thanks a lot.
    – Maksym Moroz
    Nov 21 at 7:18










  • Can you edit your original question with a reproducible example and/or the exact error message?
    – CJ Yetman
    Nov 21 at 9:49










  • But as my real graph is more bigger, unfortunately I got an error after this line of code df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd) Cannot allocate vector on some point because of lack of ram memory I suppose. Is there possible way to use my hdd memory to solve this problem?
    – Maksym Moroz
    Nov 21 at 9:53










  • Error: cannot allocate vector of size 40 Kb
    – Maksym Moroz
    Nov 21 at 10:00










  • So I have more clients names and the length of name of each client in every group is bigger than in our example, therefore my RAM ends up quickly
    – Maksym Moroz
    Nov 21 at 10:48











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394386%2fcreating-new-graph-basing-on-cluster-anylise-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










Your example code doesn't work for multiple reasons (I edited it a bit to fix some obvious problems), but I think the following achieves what you're trying to do...



library(network)
library(networkD3)
library(igraph)

df <- read.table(header = TRUE,
text = "src target
cllient1 cllient2
cllient1 cllient4
cllient1 cllient6
cllient2 cllient3
cllient4 cllient1
cllient4 cllient3
cllient5 cllient6
cllient6 cllient5")

df_graph <- graph_from_data_frame(df)

wc <- cluster_walktrap(df_graph)
members <- membership(wc)

df_graph_cntrctd <- contract(df_graph, members, vertex.attr.comb = toString)

df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd)

networkD3::forceNetwork(Links = df_graph_cntrctd_D3$links,
Nodes = df_graph_cntrctd_D3$nodes,
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'name',
opacity = 1, zoom = TRUE)


enter image description here






share|improve this answer





















  • yep, sorry for that silly mistakes.. Your suggestion solves what I was asking about :) Thanks a lot.
    – Maksym Moroz
    Nov 21 at 7:18










  • Can you edit your original question with a reproducible example and/or the exact error message?
    – CJ Yetman
    Nov 21 at 9:49










  • But as my real graph is more bigger, unfortunately I got an error after this line of code df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd) Cannot allocate vector on some point because of lack of ram memory I suppose. Is there possible way to use my hdd memory to solve this problem?
    – Maksym Moroz
    Nov 21 at 9:53










  • Error: cannot allocate vector of size 40 Kb
    – Maksym Moroz
    Nov 21 at 10:00










  • So I have more clients names and the length of name of each client in every group is bigger than in our example, therefore my RAM ends up quickly
    – Maksym Moroz
    Nov 21 at 10:48















up vote
0
down vote



accepted










Your example code doesn't work for multiple reasons (I edited it a bit to fix some obvious problems), but I think the following achieves what you're trying to do...



library(network)
library(networkD3)
library(igraph)

df <- read.table(header = TRUE,
text = "src target
cllient1 cllient2
cllient1 cllient4
cllient1 cllient6
cllient2 cllient3
cllient4 cllient1
cllient4 cllient3
cllient5 cllient6
cllient6 cllient5")

df_graph <- graph_from_data_frame(df)

wc <- cluster_walktrap(df_graph)
members <- membership(wc)

df_graph_cntrctd <- contract(df_graph, members, vertex.attr.comb = toString)

df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd)

networkD3::forceNetwork(Links = df_graph_cntrctd_D3$links,
Nodes = df_graph_cntrctd_D3$nodes,
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'name',
opacity = 1, zoom = TRUE)


enter image description here






share|improve this answer





















  • yep, sorry for that silly mistakes.. Your suggestion solves what I was asking about :) Thanks a lot.
    – Maksym Moroz
    Nov 21 at 7:18










  • Can you edit your original question with a reproducible example and/or the exact error message?
    – CJ Yetman
    Nov 21 at 9:49










  • But as my real graph is more bigger, unfortunately I got an error after this line of code df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd) Cannot allocate vector on some point because of lack of ram memory I suppose. Is there possible way to use my hdd memory to solve this problem?
    – Maksym Moroz
    Nov 21 at 9:53










  • Error: cannot allocate vector of size 40 Kb
    – Maksym Moroz
    Nov 21 at 10:00










  • So I have more clients names and the length of name of each client in every group is bigger than in our example, therefore my RAM ends up quickly
    – Maksym Moroz
    Nov 21 at 10:48













up vote
0
down vote



accepted







up vote
0
down vote



accepted






Your example code doesn't work for multiple reasons (I edited it a bit to fix some obvious problems), but I think the following achieves what you're trying to do...



library(network)
library(networkD3)
library(igraph)

df <- read.table(header = TRUE,
text = "src target
cllient1 cllient2
cllient1 cllient4
cllient1 cllient6
cllient2 cllient3
cllient4 cllient1
cllient4 cllient3
cllient5 cllient6
cllient6 cllient5")

df_graph <- graph_from_data_frame(df)

wc <- cluster_walktrap(df_graph)
members <- membership(wc)

df_graph_cntrctd <- contract(df_graph, members, vertex.attr.comb = toString)

df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd)

networkD3::forceNetwork(Links = df_graph_cntrctd_D3$links,
Nodes = df_graph_cntrctd_D3$nodes,
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'name',
opacity = 1, zoom = TRUE)


enter image description here






share|improve this answer












Your example code doesn't work for multiple reasons (I edited it a bit to fix some obvious problems), but I think the following achieves what you're trying to do...



library(network)
library(networkD3)
library(igraph)

df <- read.table(header = TRUE,
text = "src target
cllient1 cllient2
cllient1 cllient4
cllient1 cllient6
cllient2 cllient3
cllient4 cllient1
cllient4 cllient3
cllient5 cllient6
cllient6 cllient5")

df_graph <- graph_from_data_frame(df)

wc <- cluster_walktrap(df_graph)
members <- membership(wc)

df_graph_cntrctd <- contract(df_graph, members, vertex.attr.comb = toString)

df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd)

networkD3::forceNetwork(Links = df_graph_cntrctd_D3$links,
Nodes = df_graph_cntrctd_D3$nodes,
Source = 'source', Target = 'target',
NodeID = 'name', Group = 'name',
opacity = 1, zoom = TRUE)


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 1:00









CJ Yetman

3,7352529




3,7352529












  • yep, sorry for that silly mistakes.. Your suggestion solves what I was asking about :) Thanks a lot.
    – Maksym Moroz
    Nov 21 at 7:18










  • Can you edit your original question with a reproducible example and/or the exact error message?
    – CJ Yetman
    Nov 21 at 9:49










  • But as my real graph is more bigger, unfortunately I got an error after this line of code df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd) Cannot allocate vector on some point because of lack of ram memory I suppose. Is there possible way to use my hdd memory to solve this problem?
    – Maksym Moroz
    Nov 21 at 9:53










  • Error: cannot allocate vector of size 40 Kb
    – Maksym Moroz
    Nov 21 at 10:00










  • So I have more clients names and the length of name of each client in every group is bigger than in our example, therefore my RAM ends up quickly
    – Maksym Moroz
    Nov 21 at 10:48


















  • yep, sorry for that silly mistakes.. Your suggestion solves what I was asking about :) Thanks a lot.
    – Maksym Moroz
    Nov 21 at 7:18










  • Can you edit your original question with a reproducible example and/or the exact error message?
    – CJ Yetman
    Nov 21 at 9:49










  • But as my real graph is more bigger, unfortunately I got an error after this line of code df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd) Cannot allocate vector on some point because of lack of ram memory I suppose. Is there possible way to use my hdd memory to solve this problem?
    – Maksym Moroz
    Nov 21 at 9:53










  • Error: cannot allocate vector of size 40 Kb
    – Maksym Moroz
    Nov 21 at 10:00










  • So I have more clients names and the length of name of each client in every group is bigger than in our example, therefore my RAM ends up quickly
    – Maksym Moroz
    Nov 21 at 10:48
















yep, sorry for that silly mistakes.. Your suggestion solves what I was asking about :) Thanks a lot.
– Maksym Moroz
Nov 21 at 7:18




yep, sorry for that silly mistakes.. Your suggestion solves what I was asking about :) Thanks a lot.
– Maksym Moroz
Nov 21 at 7:18












Can you edit your original question with a reproducible example and/or the exact error message?
– CJ Yetman
Nov 21 at 9:49




Can you edit your original question with a reproducible example and/or the exact error message?
– CJ Yetman
Nov 21 at 9:49












But as my real graph is more bigger, unfortunately I got an error after this line of code df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd) Cannot allocate vector on some point because of lack of ram memory I suppose. Is there possible way to use my hdd memory to solve this problem?
– Maksym Moroz
Nov 21 at 9:53




But as my real graph is more bigger, unfortunately I got an error after this line of code df_graph_cntrctd_D3 <- igraph_to_networkD3(df_graph_cntrctd) Cannot allocate vector on some point because of lack of ram memory I suppose. Is there possible way to use my hdd memory to solve this problem?
– Maksym Moroz
Nov 21 at 9:53












Error: cannot allocate vector of size 40 Kb
– Maksym Moroz
Nov 21 at 10:00




Error: cannot allocate vector of size 40 Kb
– Maksym Moroz
Nov 21 at 10:00












So I have more clients names and the length of name of each client in every group is bigger than in our example, therefore my RAM ends up quickly
– Maksym Moroz
Nov 21 at 10:48




So I have more clients names and the length of name of each client in every group is bigger than in our example, therefore my RAM ends up quickly
– Maksym Moroz
Nov 21 at 10:48


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394386%2fcreating-new-graph-basing-on-cluster-anylise-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'