Depict supply network structures










2















I would like to plot a supply network structure. I have tried to use igraph, but until now did not come up with a reasonable result. An example would look like this:



library(igraph)
d <- read.table(text = "V1 V2 weight
s1 p1 88
s3 p1 100
s2 p2 100
s3 p2 43
p1 c1 21
p1 c2 79
p1 c3 88
p2 c1 22
p2 c2 121
", stringsAsFactors = F, header = T)

g <- graph_from_data_frame(d, directed = T)
plot(g, layout=layout.fruchterman.reingold,
edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Which gives:



enter image description here



The problem is that the network has an additional structure. A resonable - among others - result would show the "s"-nodes (for suppliers) should be in the left third, the "p"-nodes (plants) should be in the middle and the c-nodes (customers) on the right hand side. Is this even doable with igraph (and how)? Is there another package that could do this?










share|improve this question

















  • 1





    I think you are describing a tripartite graph. See e.g. Visualizing graph/network with 3 layeres (tripartite) in R/igraph; how to built tripartite network using .csv file in dataframe?, R is not taking the parameter hgap in layout_with_sugiyama.

    – Henrik
    Nov 14 '18 at 13:39
















2















I would like to plot a supply network structure. I have tried to use igraph, but until now did not come up with a reasonable result. An example would look like this:



library(igraph)
d <- read.table(text = "V1 V2 weight
s1 p1 88
s3 p1 100
s2 p2 100
s3 p2 43
p1 c1 21
p1 c2 79
p1 c3 88
p2 c1 22
p2 c2 121
", stringsAsFactors = F, header = T)

g <- graph_from_data_frame(d, directed = T)
plot(g, layout=layout.fruchterman.reingold,
edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Which gives:



enter image description here



The problem is that the network has an additional structure. A resonable - among others - result would show the "s"-nodes (for suppliers) should be in the left third, the "p"-nodes (plants) should be in the middle and the c-nodes (customers) on the right hand side. Is this even doable with igraph (and how)? Is there another package that could do this?










share|improve this question

















  • 1





    I think you are describing a tripartite graph. See e.g. Visualizing graph/network with 3 layeres (tripartite) in R/igraph; how to built tripartite network using .csv file in dataframe?, R is not taking the parameter hgap in layout_with_sugiyama.

    – Henrik
    Nov 14 '18 at 13:39














2












2








2








I would like to plot a supply network structure. I have tried to use igraph, but until now did not come up with a reasonable result. An example would look like this:



library(igraph)
d <- read.table(text = "V1 V2 weight
s1 p1 88
s3 p1 100
s2 p2 100
s3 p2 43
p1 c1 21
p1 c2 79
p1 c3 88
p2 c1 22
p2 c2 121
", stringsAsFactors = F, header = T)

g <- graph_from_data_frame(d, directed = T)
plot(g, layout=layout.fruchterman.reingold,
edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Which gives:



enter image description here



The problem is that the network has an additional structure. A resonable - among others - result would show the "s"-nodes (for suppliers) should be in the left third, the "p"-nodes (plants) should be in the middle and the c-nodes (customers) on the right hand side. Is this even doable with igraph (and how)? Is there another package that could do this?










share|improve this question














I would like to plot a supply network structure. I have tried to use igraph, but until now did not come up with a reasonable result. An example would look like this:



library(igraph)
d <- read.table(text = "V1 V2 weight
s1 p1 88
s3 p1 100
s2 p2 100
s3 p2 43
p1 c1 21
p1 c2 79
p1 c3 88
p2 c1 22
p2 c2 121
", stringsAsFactors = F, header = T)

g <- graph_from_data_frame(d, directed = T)
plot(g, layout=layout.fruchterman.reingold,
edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Which gives:



enter image description here



The problem is that the network has an additional structure. A resonable - among others - result would show the "s"-nodes (for suppliers) should be in the left third, the "p"-nodes (plants) should be in the middle and the c-nodes (customers) on the right hand side. Is this even doable with igraph (and how)? Is there another package that could do this?







r plot






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 13:09









r.user.05aprr.user.05apr

2,1412723




2,1412723







  • 1





    I think you are describing a tripartite graph. See e.g. Visualizing graph/network with 3 layeres (tripartite) in R/igraph; how to built tripartite network using .csv file in dataframe?, R is not taking the parameter hgap in layout_with_sugiyama.

    – Henrik
    Nov 14 '18 at 13:39













  • 1





    I think you are describing a tripartite graph. See e.g. Visualizing graph/network with 3 layeres (tripartite) in R/igraph; how to built tripartite network using .csv file in dataframe?, R is not taking the parameter hgap in layout_with_sugiyama.

    – Henrik
    Nov 14 '18 at 13:39








1




1





I think you are describing a tripartite graph. See e.g. Visualizing graph/network with 3 layeres (tripartite) in R/igraph; how to built tripartite network using .csv file in dataframe?, R is not taking the parameter hgap in layout_with_sugiyama.

– Henrik
Nov 14 '18 at 13:39






I think you are describing a tripartite graph. See e.g. Visualizing graph/network with 3 layeres (tripartite) in R/igraph; how to built tripartite network using .csv file in dataframe?, R is not taking the parameter hgap in layout_with_sugiyama.

– Henrik
Nov 14 '18 at 13:39













1 Answer
1






active

oldest

votes


















2














Yes, this is doable with igraph. One way to make your own layout. A simple way to do this is to place all "s" nodes at x=1, "p" nodes at x=2 and "c" nodes at x=3. Each distinct node of each type (s,p,c) should get a unique y value so that they do not overlap. Using your example graph:



LO = matrix(0, nrow=vcount(g), ncol=2)
LO[grep("s", V(g)$name), 1] = 1
LO[grep("p", V(g)$name), 1] = 2
LO[grep("c", V(g)$name), 1] = 3
LO[,2] = ave(rep(1, vcount(g)), LO[,1], FUN = seq_along)

plot(g, layout=LO, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Tripartite Graph



Also, following up on the comment of @Henrik, you can use layout_with_sugiyama. You still need to define the (s,p,c)-layers. Also, sugiyama arranges the layers vertically. You need to swap the x and y coordinates to get a horizontal layout.



Layers = rep(0,vcount(g))
Layers[grep("s", V(g)$name)] = 3
Layers[grep("p", V(g)$name)] = 2
Layers[grep("c", V(g)$name)] = 1
LO2 = layout_with_sugiyama(g, layers=Layers)$layout
LO2 = LO2[,2:1]

plot(g, layout=LO2, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Sugiyama layout






share|improve this answer

























  • You even did the rotation. Thx.

    – r.user.05apr
    Nov 14 '18 at 14:33










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',
autoActivateHeartbeat: false,
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%2f53301002%2fdepict-supply-network-structures%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









2














Yes, this is doable with igraph. One way to make your own layout. A simple way to do this is to place all "s" nodes at x=1, "p" nodes at x=2 and "c" nodes at x=3. Each distinct node of each type (s,p,c) should get a unique y value so that they do not overlap. Using your example graph:



LO = matrix(0, nrow=vcount(g), ncol=2)
LO[grep("s", V(g)$name), 1] = 1
LO[grep("p", V(g)$name), 1] = 2
LO[grep("c", V(g)$name), 1] = 3
LO[,2] = ave(rep(1, vcount(g)), LO[,1], FUN = seq_along)

plot(g, layout=LO, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Tripartite Graph



Also, following up on the comment of @Henrik, you can use layout_with_sugiyama. You still need to define the (s,p,c)-layers. Also, sugiyama arranges the layers vertically. You need to swap the x and y coordinates to get a horizontal layout.



Layers = rep(0,vcount(g))
Layers[grep("s", V(g)$name)] = 3
Layers[grep("p", V(g)$name)] = 2
Layers[grep("c", V(g)$name)] = 1
LO2 = layout_with_sugiyama(g, layers=Layers)$layout
LO2 = LO2[,2:1]

plot(g, layout=LO2, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Sugiyama layout






share|improve this answer

























  • You even did the rotation. Thx.

    – r.user.05apr
    Nov 14 '18 at 14:33















2














Yes, this is doable with igraph. One way to make your own layout. A simple way to do this is to place all "s" nodes at x=1, "p" nodes at x=2 and "c" nodes at x=3. Each distinct node of each type (s,p,c) should get a unique y value so that they do not overlap. Using your example graph:



LO = matrix(0, nrow=vcount(g), ncol=2)
LO[grep("s", V(g)$name), 1] = 1
LO[grep("p", V(g)$name), 1] = 2
LO[grep("c", V(g)$name), 1] = 3
LO[,2] = ave(rep(1, vcount(g)), LO[,1], FUN = seq_along)

plot(g, layout=LO, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Tripartite Graph



Also, following up on the comment of @Henrik, you can use layout_with_sugiyama. You still need to define the (s,p,c)-layers. Also, sugiyama arranges the layers vertically. You need to swap the x and y coordinates to get a horizontal layout.



Layers = rep(0,vcount(g))
Layers[grep("s", V(g)$name)] = 3
Layers[grep("p", V(g)$name)] = 2
Layers[grep("c", V(g)$name)] = 1
LO2 = layout_with_sugiyama(g, layers=Layers)$layout
LO2 = LO2[,2:1]

plot(g, layout=LO2, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Sugiyama layout






share|improve this answer

























  • You even did the rotation. Thx.

    – r.user.05apr
    Nov 14 '18 at 14:33













2












2








2







Yes, this is doable with igraph. One way to make your own layout. A simple way to do this is to place all "s" nodes at x=1, "p" nodes at x=2 and "c" nodes at x=3. Each distinct node of each type (s,p,c) should get a unique y value so that they do not overlap. Using your example graph:



LO = matrix(0, nrow=vcount(g), ncol=2)
LO[grep("s", V(g)$name), 1] = 1
LO[grep("p", V(g)$name), 1] = 2
LO[grep("c", V(g)$name), 1] = 3
LO[,2] = ave(rep(1, vcount(g)), LO[,1], FUN = seq_along)

plot(g, layout=LO, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Tripartite Graph



Also, following up on the comment of @Henrik, you can use layout_with_sugiyama. You still need to define the (s,p,c)-layers. Also, sugiyama arranges the layers vertically. You need to swap the x and y coordinates to get a horizontal layout.



Layers = rep(0,vcount(g))
Layers[grep("s", V(g)$name)] = 3
Layers[grep("p", V(g)$name)] = 2
Layers[grep("c", V(g)$name)] = 1
LO2 = layout_with_sugiyama(g, layers=Layers)$layout
LO2 = LO2[,2:1]

plot(g, layout=LO2, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Sugiyama layout






share|improve this answer















Yes, this is doable with igraph. One way to make your own layout. A simple way to do this is to place all "s" nodes at x=1, "p" nodes at x=2 and "c" nodes at x=3. Each distinct node of each type (s,p,c) should get a unique y value so that they do not overlap. Using your example graph:



LO = matrix(0, nrow=vcount(g), ncol=2)
LO[grep("s", V(g)$name), 1] = 1
LO[grep("p", V(g)$name), 1] = 2
LO[grep("c", V(g)$name), 1] = 3
LO[,2] = ave(rep(1, vcount(g)), LO[,1], FUN = seq_along)

plot(g, layout=LO, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Tripartite Graph



Also, following up on the comment of @Henrik, you can use layout_with_sugiyama. You still need to define the (s,p,c)-layers. Also, sugiyama arranges the layers vertically. You need to swap the x and y coordinates to get a horizontal layout.



Layers = rep(0,vcount(g))
Layers[grep("s", V(g)$name)] = 3
Layers[grep("p", V(g)$name)] = 2
Layers[grep("c", V(g)$name)] = 1
LO2 = layout_with_sugiyama(g, layers=Layers)$layout
LO2 = LO2[,2:1]

plot(g, layout=LO2, edge.width=E(g)$weight/20,
vertex.shape = "none", vertex.label.font = 2,
vertex.label.cex=1.1, edge.color="gray70")


Sugiyama layout







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 14:24

























answered Nov 14 '18 at 14:11









G5WG5W

22.1k82041




22.1k82041












  • You even did the rotation. Thx.

    – r.user.05apr
    Nov 14 '18 at 14:33

















  • You even did the rotation. Thx.

    – r.user.05apr
    Nov 14 '18 at 14:33
















You even did the rotation. Thx.

– r.user.05apr
Nov 14 '18 at 14:33





You even did the rotation. Thx.

– r.user.05apr
Nov 14 '18 at 14:33

















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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301002%2fdepict-supply-network-structures%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

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党