我已经调用了以下内容,它可以完美地生成一个带有networkD3的HTML文件。
forceNetwork(Links=g2$links, Nodes=g2$nodes, Source='source', Target='target', NodeID='name', Group='group', opacityNoHover=TRUE, Nodesize='group',height = 1000, width = 1000, fontSize = 20,linkDistance=200,clickAction = mcs2, zoom=TRUE) %>% saveNetwork(file = "test-network.html")
但是,在创建的HTML中,它会将浏览器和查看器的fill
参数设置为false
。
<script type="application/htmlwidget-sizing" data-for="htmlwidget-18644f4e905f10bd8c40">
{"viewer":{"width":1300,"height":1300,"padding":10,"fill":false},"browser":{"width":1300,"height":1300,"padding":10,"fill":false}}
</script>
以上内容来自生成的HTML文件,是<script>
调用生成的最终saveNetwork
标记。
如何在R中通过perl调用fill
之前更改R中的padding
和saveNetwork
值?以下是无法产生预期效果的代码。
$r->run(q`fn <- fn <- forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4, zoom = TRUE)`);
$r -> run(q`fn$sizingPolicy$viewer$fill <- TRUE`);
$r -> run(q`fn$sizingPolicy$browser$fill <- TRUE`);
$r -> run(q`saveNetwork(fn, file = "test-network.html", selfcontained=TRUE)`);
然而,这仍然会输出填充参数&#34; false&#34;。
答案 0 :(得分:1)
library(networkD3)
data(MisLinks)
data(MisNodes)
fn <- forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4, zoom = TRUE)
fn$sizingPolicy$viewer$fill <- TRUE
fn$sizingPolicy$browser$fill <- TRUE
fn$sizingPolicy$viewer$padding <- 20
fn$sizingPolicy$browser$padding <- 20
saveNetwork(fn, "forceNetwork.html", selfcontained = TRUE)
答案 1 :(得分:-1)
快速搜索显示htmlwidgets
包提供sizingPolicy
,可让您调整所需参数
像这样的东西
sizingPolicy(padding = 0, browser.fill = TRUE)