Learn R Programming

threejs (version 0.2.2)

graphjs: Interactive 3D Force-directed Graphs

Description

Plot interactive force-directed graphs.

Usage

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.

References

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

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

See Also

LeMis

Examples

Run this code
# NOT RUN {
data(LeMis)
g <- graphjs(LeMis, main="Les Misé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))
# }

Run the code above in your browser using DataLab