Вам необходимо иметь числовой столбец / переменную Value
в вашем фрейме данных Links
, и вам нужно указать его по имени с параметром Value
, равным forceNetwork()
...
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 функций. Вы можете перейти на страницу справки для forceNetwork()
, введя команду ?networkD3::forceNetwork()
в консоли. Вы можете перейти на страницу справки для любой команды, поставив перед именем функции ?
.
Ниже приведен файл справки под заголовком Использование в верхней части. Вы также можете увидеть это здесь . Обратите внимание, что все следующие аргументы не имеют значения по умолчанию и поэтому являются обязательными: 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)
В следующем разделе, Аргументы , перечислены все аргументы и даны четкие объяснения того, какие типы объектов / значений разрешены для каждого аргумента. Опять же, это касается всех функций 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.