forceNetwork networkD3-箭头问题

时间:2018-06-25 13:13:19

标签: r htmlwidgets networkd3

我正在使用软件包,并绘制了此图:

forceNetwork(Links = links, 
                      Nodes = nodes,
                      Source = "source", 
                      Target = "target",
                      NodeID = "nome",
                      Group = "tipo",
                      linkColour = links$cor,
                      Nodesize = "freq", 
                      zoom=TRUE,
                      legend = TRUE,
                      colourScale = JS(ColourScale),
                      fontSize = 14,
                      fontFamily = "serif",
                      opacity = 0.8)

enter image description here

现在,我尝试绘制带有方向箭头的图形,并设置了arrows=TRUE,但是出现了此错误。

enter image description here

有什么问题的想法吗?

这是数据的头

> head(nodes)
                       nome      tipo freq
1   Adriano Carlos De Moura Doutorado    1
2        Aline Fraiha Paiva  Mestrado    2
3              Almir Cortes Doutorado    1
4 Ana Valéria Ramos Vicente  Mestrado    1
5 André Pessoa Silva Xavier  Mestrado    1
6    Antônio Alves Sobrinho  Mestrado    1


> head(links)
                            autor                 orientador      tipo source target  cor
1               Robert Gomes Melo       Juliano Manabu IYODA  Mestrado     50     87  red
2       Cynthia Campelo Schneider     Arnaldo Daraya Contier  Mestrado     10     64  red
3 Júlio César Fernandes Vila Nova             Nelly Carvalho Doutorado     31     99 blue
4          Vanildo Almeida Mendes       Júlio Cesar de SOUZA  Mestrado     57     89  red
5          Meiriédna Queiroz Mota     Ângela Freire Prysthon  Mestrado     44     60  red
6 Júlio Cesar Fernandes Vila Nova Nelly Medeiros de Carvalho  Mestrado     30    100  red

1 个答案:

答案 0 :(得分:0)

您需要在Value数据框中有一个数字Links列/变量,并且需要使用Value的{​​{1}}参数按名称指定它。 ..

forceNetwork()

还请注意,未在帮助文件中列出默认值的函数参数是强制性的(否则会出现未指定的行为或错误)。这适用于R中的所有函数,而不仅仅是函数。您可以通过在控制台中输入命令library(networkD3) nodes <- read.csv(header = TRUE, text = " nome,tipo,freq Adriano Carlos De Moura,Doutorado,1 Aline Fraiha Paiva,Mestrado,2 Almir Cortes,Doutorado,1 Ana Valéria Ramos Vicente,Mestrado,1 André Pessoa Silva Xavier,Mestrado,1 Antônio Alves Sobrinho,Mestrado,1 ") links <- read.csv(header = TRUE, text = " autor,orientador,tipo,source,target,cor Robert Gomes Melo,Juliano Manabu IYODA,Mestrado,0,1,red Cynthia Campelo Schneider,Arnaldo Daraya Contier,Mestrado,2,3,red Júlio César Fernandes Vila Nova,Nelly Carvalho,Doutorado,4,5,blue ") links$value = 1 forceNetwork(Links = links, Nodes = nodes, Source = "source", Target = "target", NodeID = "nome", Group = "tipo", Value = "value", # linkColour = links$cor, Nodesize = "freq", zoom=TRUE, legend = TRUE, # colourScale = JS(ColourScale), fontSize = 14, fontFamily = "serif", opacity = 0.8, arrows = TRUE) 进入forceNetwork()的帮助页面。您可以在函数名称前加上?networkD3::forceNetwork()来访问任何命令的帮助页面。

以下是帮助文件在顶部附近的用法标题下显示的内容。您也可以here看到它。请注意,以下所有参数均没有默认值,因此是必填参数:?LinksNodesSourceTarget,{{ 1}},ValueNodeID

Nodesize

以下部分自变量列出了每个自变量,并给出了每个自变量允许使用的对象/值类型的明确说明。同样,这适用于所有R函数,而不仅仅是函数。看起来就是这样...

Group