forceNetwork networkD3 - 箭头问题
forceNetwork networkD3 - Arrow issue
我正在使用 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)
现在我尝试用定向箭头绘制图形,并且设置了 arrows=TRUE
,但是出现了这个错误。
有什么问题吗?
这是数据的头部
> 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
您的 Links
数据框中需要有一个数字 Value
column/variable,并且您需要使用 Value
的 [=] 参数按名称指定它16=]...
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)
另请注意,在帮助文件中未列出默认值的函数参数是强制性的(否则您会得到未指定的行为或错误)。这适用于 R 中的所有函数,而不仅仅是 networkd3 函数。您可以通过在控制台中键入命令 ?networkD3::forceNetwork()
来访问 forceNetwork()
的帮助页面。您可以通过在函数名称前加上 ?
.
来访问任何命令的帮助页面
下面是帮助文件在靠近顶部的用法 标题下显示的内容。也可以看看here。请注意,以下所有参数都没有默认值,因此是必需的:Links
、Nodes
、Source
、Target
、Value
、NodeID
, Nodesize
, Group
.
forceNetwork(Links, Nodes, Source, Target, Value, NodeID, Nodesize, Group,
height = NULL, width = NULL,
colourScale = JS("d3.scaleOrdinal(d3.schemeCategory20);"), fontSize = 7,
fontFamily = "serif", linkDistance = 50,
linkWidth = JS("function(d) { return Math.sqrt(d.value); }"),
radiusCalculation = JS(" Math.sqrt(d.nodesize)+6"), charge = -30,
linkColour = "#666", opacity = 0.6, zoom = FALSE, legend = FALSE,
arrows = FALSE, bounded = FALSE, opacityNoHover = 0,
clickAction = NULL)
下一节 Arguments 列出了每个参数,并明确解释了每个参数允许的 objects/values 类型。同样,这适用于所有 R 函数,而不仅仅是 networkd3 函数。这就是它的样子...
Links a data frame object with the links between the nodes. It should include the Source and Target for each link. These should be numbered starting from 0. An optional Value variable can be included to specify how close the nodes are to one another.
Nodes a data frame containing the node id and properties of the nodes. If no ID is specified then the nodes must be in the same order as the Source variable column in the Links data frame. Currently only a grouping variable is allowed.
Source character string naming the network source variable in the Links data frame.
Target character string naming the network target variable in the Links data frame.
Value character string naming the variable in the Links data frame for how wide the links are.
NodeID character string specifying the node IDs in the Nodes data frame.
Nodesize character string specifying the a column in the Nodes data frame with some value to vary the node radius's with. See also radiusCalculation.
Group character string specifying the group of each node in the Nodes data frame.
height numeric height for the network graph's frame area in pixels.
width numeric width for the network graph's frame area in pixels.
colourScale character string specifying the categorical colour scale for the nodes. See https://github.com/d3/d3/blob/master/API.md#ordinal-scales.
fontSize numeric font size in pixels for the node text labels.
fontFamily font family for the node text labels.
linkDistance numeric or character string. Either numberic fixed distance between the links in pixels (actually arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. For example: linkDistance = JS("function(d){return d.value * 10}").
linkWidth numeric or character string. Can be a numeric fixed width in pixels (arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. The default is linkWidth = JS("function(d) { return Math.sqrt(d.value); }").
radiusCalculation character string. A javascript mathematical expression, to weight the radius by Nodesize. The default value is radiusCalculation = JS("Math.sqrt(d.nodesize)+6").
charge numeric value indicating either the strength of the node repulsion (negative value) or attraction (positive value).
linkColour character vector specifying the colour(s) you want the link lines to be. Multiple formats supported (e.g. hexadecimal).
opacity numeric value of the proportion opaque you would like the graph elements to be.
zoom logical value to enable (TRUE) or disable (FALSE) zooming.
legend logical value to enable node colour legends.
arrows logical value to enable directional link arrows.
bounded logical value to enable (TRUE) or disable (FALSE) the bounding box limiting the graph's extent. See http://bl.ocks.org/mbostock/1129492.
opacityNoHover numeric value of the opacity proportion for node labels text when the mouse is not hovering over them.
clickAction character string with a JavaScript expression to evaluate when a node is clicked.
我正在使用 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)
现在我尝试用定向箭头绘制图形,并且设置了 arrows=TRUE
,但是出现了这个错误。
有什么问题吗?
这是数据的头部
> 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
您的 Links
数据框中需要有一个数字 Value
column/variable,并且您需要使用 Value
的 [=] 参数按名称指定它16=]...
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)
另请注意,在帮助文件中未列出默认值的函数参数是强制性的(否则您会得到未指定的行为或错误)。这适用于 R 中的所有函数,而不仅仅是 networkd3 函数。您可以通过在控制台中键入命令 ?networkD3::forceNetwork()
来访问 forceNetwork()
的帮助页面。您可以通过在函数名称前加上 ?
.
下面是帮助文件在靠近顶部的用法 标题下显示的内容。也可以看看here。请注意,以下所有参数都没有默认值,因此是必需的:Links
、Nodes
、Source
、Target
、Value
、NodeID
, Nodesize
, Group
.
forceNetwork(Links, Nodes, Source, Target, Value, NodeID, Nodesize, Group,
height = NULL, width = NULL,
colourScale = JS("d3.scaleOrdinal(d3.schemeCategory20);"), fontSize = 7,
fontFamily = "serif", linkDistance = 50,
linkWidth = JS("function(d) { return Math.sqrt(d.value); }"),
radiusCalculation = JS(" Math.sqrt(d.nodesize)+6"), charge = -30,
linkColour = "#666", opacity = 0.6, zoom = FALSE, legend = FALSE,
arrows = FALSE, bounded = FALSE, opacityNoHover = 0,
clickAction = NULL)
下一节 Arguments 列出了每个参数,并明确解释了每个参数允许的 objects/values 类型。同样,这适用于所有 R 函数,而不仅仅是 networkd3 函数。这就是它的样子...
Links a data frame object with the links between the nodes. It should include the Source and Target for each link. These should be numbered starting from 0. An optional Value variable can be included to specify how close the nodes are to one another.
Nodes a data frame containing the node id and properties of the nodes. If no ID is specified then the nodes must be in the same order as the Source variable column in the Links data frame. Currently only a grouping variable is allowed.
Source character string naming the network source variable in the Links data frame.
Target character string naming the network target variable in the Links data frame.
Value character string naming the variable in the Links data frame for how wide the links are.
NodeID character string specifying the node IDs in the Nodes data frame.
Nodesize character string specifying the a column in the Nodes data frame with some value to vary the node radius's with. See also radiusCalculation.
Group character string specifying the group of each node in the Nodes data frame.
height numeric height for the network graph's frame area in pixels.
width numeric width for the network graph's frame area in pixels.
colourScale character string specifying the categorical colour scale for the nodes. See https://github.com/d3/d3/blob/master/API.md#ordinal-scales.
fontSize numeric font size in pixels for the node text labels.
fontFamily font family for the node text labels.
linkDistance numeric or character string. Either numberic fixed distance between the links in pixels (actually arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. For example: linkDistance = JS("function(d){return d.value * 10}").
linkWidth numeric or character string. Can be a numeric fixed width in pixels (arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. The default is linkWidth = JS("function(d) { return Math.sqrt(d.value); }").
radiusCalculation character string. A javascript mathematical expression, to weight the radius by Nodesize. The default value is radiusCalculation = JS("Math.sqrt(d.nodesize)+6").
charge numeric value indicating either the strength of the node repulsion (negative value) or attraction (positive value).
linkColour character vector specifying the colour(s) you want the link lines to be. Multiple formats supported (e.g. hexadecimal).
opacity numeric value of the proportion opaque you would like the graph elements to be.
zoom logical value to enable (TRUE) or disable (FALSE) zooming.
legend logical value to enable node colour legends.
arrows logical value to enable directional link arrows.
bounded logical value to enable (TRUE) or disable (FALSE) the bounding box limiting the graph's extent. See http://bl.ocks.org/mbostock/1129492.
opacityNoHover numeric value of the opacity proportion for node labels text when the mouse is not hovering over them.
clickAction character string with a JavaScript expression to evaluate when a node is clicked.