如何使用networkD3在R中绘制有向图? [英] How to plot a directed Graph in R with networkD3?

查看:154
本文介绍了如何使用networkD3在R中绘制有向图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用NetworkD3绘制有向图时,边缘没有方向,如何解决? 一个示例:

when I am ploting a directed graph with NetworkD3 , The edges are not directed , how can I fix it ? an Example :

library(networkD3)
data(MisLinks)
data(MisNodes)
forceNetwork(Links = MisLinks, Nodes = MisNodes,
         Source = "source", Target = "target",
         Value = "value", NodeID = "name",
         Group = "group", opacity = 0.8)

我希望结果是有向的这是有向图的定义:

I want the result to be directed This is the definetion of directed Graph:

有向图是图,即一组连接在一起的对象(称为顶点或节点),其中所有边从一个顶点指向另一个顶点.有向图有时称为有向图或有向图网络."

"A directed graph is graph, i.e., a set of objects (called vertices or nodes) that are connected together, where all the edges are directed from one vertex to another. A directed graph is sometimes called a digraph or a directed network."

我希望边缘像箭头一样,我该如何在networkD3中做到这一点,希望它清楚.

I want the edges be like arrows , how can i do it in networkD3 , I hope it's clear.

谢谢.

推荐答案

networkD3软件包的forceNetwork()函数不会在有向图的链接上绘制箭头.我可以肯定地说这是因为我是该程序包的当前活跃开发人员之一,并且我非常了解该功能及其选项.您还可以在R控制台中运行?networkD3::forceNetwork,以查看帮助文件和forceNetwork()函数的所有可能选项.

The forceNetwork() function of the networkD3 package does not draw arrows on the links for directed graphs. I can say that quite definitively because I am one of the currently active developers working on the package and I know the function and its options very well. You can also run ?networkD3::forceNetwork in your R console to see the help file and all of the possible options for the forceNetwork() function.

更新(2017.03.20)

此功能(有向图的绘制箭头)现在是networkD3的CRAN官方发行版的一部分.安装后,您可以使用带有...的箭头来绘制有向力网络.

This feature (plotting arrows for a directed graph) is now part of the official CRAN release version of networkD3. Once installed, you can plot a directed forceNetwork with arrows with...

library(networkD3)
URL <- paste0("https://cdn.rawgit.com/christophergandrud/networkD3/",
              "master/JSONdata/miserables.json")
MisJson <- jsonlite::fromJSON(URL)
ValjeanInds <- which(MisJson$links == 11, arr = TRUE)[, 1]
ValjeanCols <- ifelse(1:nrow(MisJson$links) %in% ValjeanInds, "#bf3eff", "#666")

forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source", Target = "target", 
             Value = "value", NodeID = "name", Group = "group", opacity = 0.8, 
             linkColour = ValjeanCols, arrows = TRUE, zoom = TRUE)

它应该看起来像...

and it should look like...

这篇关于如何使用networkD3在R中绘制有向图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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