R visNetwork:多个图形布局? [英] R visNetwork: Multiple graph layout?

查看:84
本文介绍了R visNetwork:多个图形布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想并排放置两个visNetwork图,以进行视觉比较.使用带有par()或layout()的igraph可以进行多图定位.有没有办法为visNetwork做到这一点?变通/杂音(包括RShiny等)是可接受的答案-可以并排显示visNetwork的任何方法.请注意,ID号等重叠,因此将两个网络置于同一个图形中将是我希望避免的大量数据操作.

I would like to position two visNetwork plots side-by-side for visual comparison. Multi-plot positioning is possible using igraph with par() or layout(). Is there a way to do this for visNetwork? Work-arounds/kludges (including RShiny, etc.) are acceptable answers - whatever works to provide a side-by-side visNetwork display. Note that ID numbers etc. overlap, so putting both networks into the same graph would be a lot of data manipulation that I wish to avoid.

这是我要尝试做的事情的一个例子.

Here is an example of the type of thing I am trying to do.

library(visNetwork)

# Network 1
nodes1 <- data.frame(id = 1:3)
edges1 <- data.frame(from = c(1,1), to = c(2,3))

# Network 2
nodes2 <- data.frame(id = 1:4)
edges2 <- data.frame(from = c(1,1,2,2), to = c(2,3,4,3))

# Plot both networks side-by-side?
par(mfrow=c(1,2))  # Want something like this (does not work)
visNetwork(nodes1, edges1) %>% visEdges(arrows = 'from')  
visNetwork(nodes2, edges2) %>% visEdges(arrows = 'from')

干杯,蒂姆

推荐答案

如果给出了完全的自由,我会选择 flexdashboard .这是一个方便的 rmarkdown 模板,用于创建交互式仪表板,从简单快速的仪表板到复杂的复杂仪表板.

If complete liberty is given I'd go with flexdashboard. It's a handy rmarkdown template to create interactive dashboards, from simple and quick ones to elaborate and complex.

install.packages('flexdashboard')

然后从模板'Flex Dashboard'创建新的 Rmd ,或将以下内容复制到新的 .Rmd 文件

Then either create a new Rmd from template 'Flex Dashboard', or copy the following into a new .Rmd file

---
title: "DASHBOARD"
output: 
    flexdashboard::flex_dashboard:
        orientation: rows
---

```{r, echo=FALSE}
library(visNetwork)

# Network 1
nodes1 <- data.frame(id = 1:3)
edges1 <- data.frame(from = c(1,1), to = c(2,3))

# Network 2
nodes2 <- data.frame(id = 1:4)
edges2 <- data.frame(from = c(1,1,2,2), to = c(2,3,4,3))

```

Row 
-------------------------------------

### Chart 1

```{r}
visNetwork(nodes1, edges1) %>% visEdges(arrows = 'from')
```


### Chart 2

```{r}
visNetwork(nodes2, edges2) %>% visEdges(arrows = 'from')
```

请注意,由于布局是响应式的,因此Rstudio的查看器"窗格中的默认视图会垂直堆叠图形,但是扩展窗格或在外部浏览器中打开它们会并排显示它们.

Note that as the layout is responsive the default view in the Viewer pane in Rstudio stack the graphs vertically, but extending the pane or opening it in an external browser shows them side by side.

这篇关于R visNetwork:多个图形布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆