R中的原力网络



我已经调用了以下内容,它完美地制作了一个带有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 文件,是从saveNetwork调用生成的最终<script>标记。

在通过 perl 在 R 中调用 saveNetwork 之前,如何更改 R 中的fillpadding值?下面是不会产生所需效果的代码。

$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)`);

但是,这仍然输出带有"false"的填充参数。

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)

快速搜索显示htmlwidgets包提供了允许您调整所需参数的sizingPolicy

像这样的东西

sizingPolicy(padding = 0, browser.fill = TRUE)

相关内容

  • 没有找到相关文章