Interactive 3D Force-directed Graphs

Share:

Description

Plot interactive force-directed graphs.

Usage

1
2
3
4
graphjs(edges, nodes, main = "", curvature = 0, bg = "white",
  fg = "black", showLabels = FALSE, attraction = 1, repulsion = 1,
  max_iterations = 1500, opacity = 1, stroke = TRUE, width = NULL,
  height = NULL)

Arguments

edges

Either a list with edges and nodes data frames as described below, or a graph object produced from the igraph package (see igraph2graphjs), or an edge data frame with at least columns:

  • from Integer node id identifying edge 'from' node

  • to Integer node id identifying the edge 'to' node

  • size Nonnegative numeric edge line width

  • color Edge color specified like node color above

Each row of the data frame identifies a graph edge.

nodes

Optional node (vertex) data frame with at least columns:

  • label Node character labels

  • id Unique integer node ids (corresponding to node ids used by edges)

  • size Positive numeric node plot size

  • color A character color value, either color names ("blue", "red", ...) or 3-digit hexadecimal values ("#0000FF", "#EE0011")

Each row of the data frame defines a graph node. If the nodes argument is missing it will be inferred from the edges argument.

main

Plot title

curvature

Zero implies that edges are straight lines. Specify a positive number to curve the edges, useful to distinguish multiple edges in directed graphs (the z-axis of the curve depends on the sign of edge$from - edge$to). Larger numbers = more curvature, with 1 a usually reasonable value.

bg

Plot background color specified similarly to the node colors described above

fg

Plot foreground text color

showLabels

If TRUE then display text labels near each node

attraction

Numeric value specifying attraction of connected nodes to each other, larger values indicate more attraction

repulsion

Numeric value specifying repulsion of all nodes to each other, larger values indicate greater repulsion

max_iterations

Integer value specifying the maximum number of rendering iterations before stopping

opacity

Node transparency, 0 <= opacity <= 1

stroke

If TRUE, stroke each node with a black circle

width

optional widget width

height

optional widget height

Value

An htmlwidget object that is displayed using the object's show or print method. (If you don't see your widget plot, try printing it with the print) function.

Note

All colors must be specified as color names like "red", "blue", etc. or as hexadecimal color values without opacity channel, for example "#FF0000", "#0a3e55" (upper or lower case hex digits are allowed).

The plot responds to the following mouse controls (touch analogs may also be supported on some systems):

  • scrollwheel zoom

  • left-mouse button + move rotate

  • right-mouse button + move pan

  • mouse over identify node by appending its label to the title

Double-click or tap on the plot to reset the view.

Basic support for plotting igraph objects is provided by the igraph2graphjs function.

References

Original code by David Piegza: https://github.com/davidpiegza/Graph-Visualization.

The three.js project http://threejs.org.

See Also

LeMis

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
data(LeMis)
g <- graphjs(LeMis, main="Les Mis&eacute;rables", showLabels=TRUE)
print(g)

## Not run: 
# The next example uses the `igraph` package.
library(igraph)
set.seed(1)
g <- sample_islands(3, 10, 5/10, 1)
i <- cluster_optimal(g)
g <- set_vertex_attr(g, "color", value=c("yellow", "green", "blue")[i$membership])
print(graphjs(g))

## End(Not run)