更改 networkD3 的背景颜色可以通过劫持 forceNetwork 函数的一些参数来实现,如下所示@Jota:更改 networkD3 图的背景颜色。
这将如何外推到更改背景图像?
我尝试了几种方法但没有成功,其中一种如下:
library(networkD3)
library(htmltools)
data(MisLinks)
data(MisNodes)
browsable(
tagList(
forceNetwork(Links = MisLinks, Nodes = MisNodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
Group = "group", opacity = 0.8),
tags$script('document.body.style.backgroundImage = "url(paper.gif)"')
)
)
有没有办法以类似的方式更改背景图像,如下所示:
linkDistance = JS('function(({d3.select("body"(.style("background-color", "#910e33"(; return 50;}'(( ?
您必须完全指定 URL。例如,这似乎有效...
library(networkD3)
library(htmltools)
data(MisLinks)
data(MisNodes)
browsable(
tagList(
forceNetwork(Links = MisLinks, Nodes = MisNodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
Group = "group", opacity = 0.8),
tags$script('document.body.style.backgroundImage = "url(https://media.giphy.com/media/dgrEGTo4uk22Y/giphy.gif)"')
)
)
这是另一种不使用htmltools
的方法...
library(networkD3)
data(MisLinks)
data(MisNodes)
linkJS <- JS('
function(){
d3.select("body")
.style("background-image", "url(https://media.giphy.com/media/dgrEGTo4uk22Y/giphy.gif)")
.style("background-repeat", "no-repeat")
.style("background-position", "right bottom");
return 50;
}')
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.8, linkDistance = linkJS)