Add gradient to links in R networkD3::sankeyNetwork?












0















Within the R environment, is there any way to add gradients to links with user-specified colors within the networkD3::sankeyNetwork functions?



This repo expands on the functions of networkD3::sankeyNetwork, but it only seems to allow for the linkGradient parameter when the LinkGroup parameter isn't used, i.e. you can only use the gradient when all links are the same color. Unfortunately, I require LinkGroup to specify a different color for each link.



Here's a reproducible example of a Sankey diagram with user-specified colors for the links, but without the gradient that I'm trying to impose.



source = as.numeric(c("0", "0", "0", "0"))
target = as.numeric(c("1", "2", "3", "4"))
value = as.numeric(c("40", "10", "5", "20"))
group = c("red", "yellow", "green", "blue")
node = as.numeric(c("0", "1", "2", "3", "4"))
name = c("source", "red", "yellow", "green", "blue")

links = data.frame(source, target, value, group)
nodes = data.frame(node, name)

networkD3::sankeyNetwork(Links = links, Nodes = nodes,
Source = 'source',
Target = 'target',
Value = 'value',
NodeID = 'name',
units = 'UOM',
LinkGroup = 'group',
colourScale = JS('d3.scaleOrdinal()
.domain(["miRNA","red", "yellow", "green", "blue"])
.range(["black", "red", "yellow","green","blue"])'))


Edit: Yes, there is a java option here, but I'm looking for a solution within the R environment, i.e. via R, not java. Further, that solution doesn't work well with heavily curved links. The aforementioned repo provides a much smoother gradient with curved lines. I don't know how to modify from there to allow for multiple colored links with a gradient.










share|improve this question

























  • Possible duplicate of Gradient along links in D3 Sankey diagram

    – CJ Yetman
    Nov 21 '18 at 13:35











  • Basically, it cannot be done in R, not directly anyway. networkD3 just passes the data and a few options into the JavaScript code. To achieve this, you would have to (heavily) modify the underlying JavaScript code.

    – CJ Yetman
    Nov 22 '18 at 21:12
















0















Within the R environment, is there any way to add gradients to links with user-specified colors within the networkD3::sankeyNetwork functions?



This repo expands on the functions of networkD3::sankeyNetwork, but it only seems to allow for the linkGradient parameter when the LinkGroup parameter isn't used, i.e. you can only use the gradient when all links are the same color. Unfortunately, I require LinkGroup to specify a different color for each link.



Here's a reproducible example of a Sankey diagram with user-specified colors for the links, but without the gradient that I'm trying to impose.



source = as.numeric(c("0", "0", "0", "0"))
target = as.numeric(c("1", "2", "3", "4"))
value = as.numeric(c("40", "10", "5", "20"))
group = c("red", "yellow", "green", "blue")
node = as.numeric(c("0", "1", "2", "3", "4"))
name = c("source", "red", "yellow", "green", "blue")

links = data.frame(source, target, value, group)
nodes = data.frame(node, name)

networkD3::sankeyNetwork(Links = links, Nodes = nodes,
Source = 'source',
Target = 'target',
Value = 'value',
NodeID = 'name',
units = 'UOM',
LinkGroup = 'group',
colourScale = JS('d3.scaleOrdinal()
.domain(["miRNA","red", "yellow", "green", "blue"])
.range(["black", "red", "yellow","green","blue"])'))


Edit: Yes, there is a java option here, but I'm looking for a solution within the R environment, i.e. via R, not java. Further, that solution doesn't work well with heavily curved links. The aforementioned repo provides a much smoother gradient with curved lines. I don't know how to modify from there to allow for multiple colored links with a gradient.










share|improve this question

























  • Possible duplicate of Gradient along links in D3 Sankey diagram

    – CJ Yetman
    Nov 21 '18 at 13:35











  • Basically, it cannot be done in R, not directly anyway. networkD3 just passes the data and a few options into the JavaScript code. To achieve this, you would have to (heavily) modify the underlying JavaScript code.

    – CJ Yetman
    Nov 22 '18 at 21:12














0












0








0








Within the R environment, is there any way to add gradients to links with user-specified colors within the networkD3::sankeyNetwork functions?



This repo expands on the functions of networkD3::sankeyNetwork, but it only seems to allow for the linkGradient parameter when the LinkGroup parameter isn't used, i.e. you can only use the gradient when all links are the same color. Unfortunately, I require LinkGroup to specify a different color for each link.



Here's a reproducible example of a Sankey diagram with user-specified colors for the links, but without the gradient that I'm trying to impose.



source = as.numeric(c("0", "0", "0", "0"))
target = as.numeric(c("1", "2", "3", "4"))
value = as.numeric(c("40", "10", "5", "20"))
group = c("red", "yellow", "green", "blue")
node = as.numeric(c("0", "1", "2", "3", "4"))
name = c("source", "red", "yellow", "green", "blue")

links = data.frame(source, target, value, group)
nodes = data.frame(node, name)

networkD3::sankeyNetwork(Links = links, Nodes = nodes,
Source = 'source',
Target = 'target',
Value = 'value',
NodeID = 'name',
units = 'UOM',
LinkGroup = 'group',
colourScale = JS('d3.scaleOrdinal()
.domain(["miRNA","red", "yellow", "green", "blue"])
.range(["black", "red", "yellow","green","blue"])'))


Edit: Yes, there is a java option here, but I'm looking for a solution within the R environment, i.e. via R, not java. Further, that solution doesn't work well with heavily curved links. The aforementioned repo provides a much smoother gradient with curved lines. I don't know how to modify from there to allow for multiple colored links with a gradient.










share|improve this question
















Within the R environment, is there any way to add gradients to links with user-specified colors within the networkD3::sankeyNetwork functions?



This repo expands on the functions of networkD3::sankeyNetwork, but it only seems to allow for the linkGradient parameter when the LinkGroup parameter isn't used, i.e. you can only use the gradient when all links are the same color. Unfortunately, I require LinkGroup to specify a different color for each link.



Here's a reproducible example of a Sankey diagram with user-specified colors for the links, but without the gradient that I'm trying to impose.



source = as.numeric(c("0", "0", "0", "0"))
target = as.numeric(c("1", "2", "3", "4"))
value = as.numeric(c("40", "10", "5", "20"))
group = c("red", "yellow", "green", "blue")
node = as.numeric(c("0", "1", "2", "3", "4"))
name = c("source", "red", "yellow", "green", "blue")

links = data.frame(source, target, value, group)
nodes = data.frame(node, name)

networkD3::sankeyNetwork(Links = links, Nodes = nodes,
Source = 'source',
Target = 'target',
Value = 'value',
NodeID = 'name',
units = 'UOM',
LinkGroup = 'group',
colourScale = JS('d3.scaleOrdinal()
.domain(["miRNA","red", "yellow", "green", "blue"])
.range(["black", "red", "yellow","green","blue"])'))


Edit: Yes, there is a java option here, but I'm looking for a solution within the R environment, i.e. via R, not java. Further, that solution doesn't work well with heavily curved links. The aforementioned repo provides a much smoother gradient with curved lines. I don't know how to modify from there to allow for multiple colored links with a gradient.







r sankey-diagram networkd3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 15:31







Marion

















asked Nov 21 '18 at 12:49









MarionMarion

12




12













  • Possible duplicate of Gradient along links in D3 Sankey diagram

    – CJ Yetman
    Nov 21 '18 at 13:35











  • Basically, it cannot be done in R, not directly anyway. networkD3 just passes the data and a few options into the JavaScript code. To achieve this, you would have to (heavily) modify the underlying JavaScript code.

    – CJ Yetman
    Nov 22 '18 at 21:12



















  • Possible duplicate of Gradient along links in D3 Sankey diagram

    – CJ Yetman
    Nov 21 '18 at 13:35











  • Basically, it cannot be done in R, not directly anyway. networkD3 just passes the data and a few options into the JavaScript code. To achieve this, you would have to (heavily) modify the underlying JavaScript code.

    – CJ Yetman
    Nov 22 '18 at 21:12

















Possible duplicate of Gradient along links in D3 Sankey diagram

– CJ Yetman
Nov 21 '18 at 13:35





Possible duplicate of Gradient along links in D3 Sankey diagram

– CJ Yetman
Nov 21 '18 at 13:35













Basically, it cannot be done in R, not directly anyway. networkD3 just passes the data and a few options into the JavaScript code. To achieve this, you would have to (heavily) modify the underlying JavaScript code.

– CJ Yetman
Nov 22 '18 at 21:12





Basically, it cannot be done in R, not directly anyway. networkD3 just passes the data and a few options into the JavaScript code. To achieve this, you would have to (heavily) modify the underlying JavaScript code.

– CJ Yetman
Nov 22 '18 at 21:12












0






active

oldest

votes











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%2f53412403%2fadd-gradient-to-links-in-r-networkd3sankeynetwork%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53412403%2fadd-gradient-to-links-in-r-networkd3sankeynetwork%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







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini