Learn R Programming

qgraph (version 1.10.1)

qgraphHTML: Interactive HTML output for qgraph graphs

Description

Exports a qgraph object to a self-contained interactive HTML file. The graph is rendered as SVG with exactly the layout and style of the corresponding R plot (node placement, colors, node and edge sizes, curvature, line types, labels and edge labels), and supports:

  • dragging nodes (edges follow),

  • selecting a node by clicking it, with two highlight modes that can be toggled: highlighting the node with its direct connections, or highlighting all outgoing shortest paths from that node (using inverse absolute edge weights as distances, respecting edge directions),

  • tooltips showing the node label, the node name (nodeNames) and an optional custom text (tooltips argument of qgraph),

  • saving the current view as an SVG or PNG file,

  • an interactive legend (in the "rich" version) in which groups and nodes can be clicked to highlight them.

The file has no external dependencies and can be opened offline in any modern browser. This function is also called by qgraph and plot.qgraph when filetype = "html" is used.

Usage

qgraphHTML(x, filename = "qgraph.html", htmltype = c("rich", "plain"),
           open = interactive(), verbose = TRUE)

Value

The path of the written file, invisibly.

Arguments

x

A "qgraph" object, as returned (invisibly) by qgraph.

filename

Name of the output file. The extension .html is added if not present. Note that when this function is called via qgraph(..., filetype = "html"), the filename argument of qgraph is used (without extension), as for the other file types.

htmltype

"rich" (default) writes a full viewer with a toolbar (highlight-mode toggle, reset layout, save SVG/PNG) and an interactive legend panel. "plain" writes a minimal page containing only the interactive graph, suitable for embedding in another page (e.g., in an <iframe>); in the plain version the highlight mode can be toggled with the m key or by shift-clicking a node.

open

Logical; open the resulting file in the default browser?

verbose

Logical; print a message with the location of the output file?

Author

Sacha Epskamp <mail@sachaepskamp.com>

Details

Most graphical attributes are reproduced exactly from the qgraph object. A small number of plot elements are approximated or not (yet) supported in the HTML output: means/SDs bars inside nodes, knots (tied edges), subplots and images as nodes, and the XKCD style. Self-loop and arrowhead geometry are close approximations of their R counterparts.

See Also

qgraph

Examples

Run this code
if (FALSE) {
data(big5)
data(big5groups)
Q <- qgraph(cor(big5), minimum = 0.25, groups = big5groups,
            nodeNames = colnames(big5), legend = TRUE, DoNotPlot = TRUE)

# Rich interactive viewer:
qgraphHTML(Q, "big5.html")

# Minimal embeddable version:
qgraphHTML(Q, "big5_plain.html", htmltype = "plain")

# Equivalently, directly from qgraph:
qgraph(cor(big5), minimum = 0.25, groups = big5groups,
       nodeNames = colnames(big5), filetype = "html", filename = "big5")
}

Run the code above in your browser using DataLab