New features in qgraph 1.2
R plots as nodes
subplots argument can be used to evaluate R expressions that create plots as nodes. This is done using the
subplot function from the Hmisc package.
This can have many applications. For example, it could be used to show a histogram or the analytic distribution of the represented node:
qgraph(matrix(1, 3, 3), subplots = list(expression(curve(dgamma(x, 2, 2), 0, 4, main = "")), expression(hist(rnorm(100), main = "")), NULL), vsize = 20)
Use images as nodes
Two years ago there was a popular question on Stackoverflow on how to plot images as nodes. Now with the subplots argument implemented, this can be done internally.
# Download R logo: download.file("http://cran.r-project.org/Rlogo.jpg", file <- tempfile(fileext = ".jpg"), mode = "wb") # Sample an adjacency matrix: set.seed(1) adj <- matrix(sample(0:1, 10^2, TRUE, prob = c(0.8, 0.2)), 10, 10) # Run qgraph: qgraph(adj, images = file, labels = FALSE, borders = FALSE)
You can either use one image for all nodes or a separate image for each node. Doing this overwrites
"rectangle" (which is also new in this version).
Knotting edges together
knots argument can be used to tie edges together at their center. This could have many applications, such as representing an edge with three attached nodes or bundling similar edges together. In particular, it is used in the new semPlot package to represent interaction effects.
# Edgelist: E <- cbind(c(1, 2, 1, 2), 3) # Indicate edge 3 and 4 should be tied together: Knots <- c(0, 0, 1, 1) qgraph(E, knots = Knots, layout = "circle")
Custom edge colors
A long time request was for users to be able to change the default green and red color scheme. Well, now you can! The arguments
unCol can be used to set default colors for positive, negative and unweighted edges respectively. These edge colors will still fade to white or invisible as their absolute weight approaches the minimum:
data(big5) data(big5groups) qgraph(cor(big5), minimum = 0.25, cut = 0.4, vsize = 1.5, groups = big5groups, legend = FALSE, borders = FALSE, posCol = "blue", negCol = "purple", labels = FALSE)
In addition, there were some changes to
edge.color as well. It can now be used to overwrite specific color edges,
NA indicates that a color should be colored by default. In addition, the colors now also fade to white or transparency unless
fade = FALSE.
Default arguments can now be set for all graphs by assigning a named list to the option
qgraph. For example, if we really grew fond of our blue and purple color scheme and in addition would like a black background:
options(qgraph = list(bg = "black", posCol = "blue", negCol = "purple")) qgraph(cor(big5), minimum = 0.25, cut = 0.4, vsize = 1.5, groups = big5groups, legend = FALSE, borders = FALSE, labels = FALSE)
To restore defaults assign an empty list:
options(qgraph = list())
qgraph was always intended to be easily usable with the fantastic igraph package (the first version was even simply a wrapper function around igraph). To further facilitate this I have included support for igraph functionality. First. the
as.igraph function can be used to convert a
qgraph object to an
igraph object, which can be used to use the many graph analysis functions in igraph. Secondly, igraph layout functions can now be used directly in the layout argument (they were usable before in that their output was compatible with qgraph).
# Load igraph: library("igraph") # Create random network: set.seed(1) adj <- matrix(sample(0:1, 10^2, TRUE, prob = c(0.8, 0.2)), 10, 10) # Run qgraph with igraph layout function: Graph <- qgraph(adj, layout = layout.kamada.kawai)
# Convert graph: Graph <- as.igraph(Graph) # Compute some graph statistics: transitivity(Graph)
##  0.2571
##  0.03704 0.03125 0.01111 0.03704 0.03030 0.03704 0.03571 0.02564 ##  0.04000 0.03448
Expressions as labels
R expressions can now be used as labels. This means it is easy to add mathematical to your graphs now. For example:
qgraph(matrix(1, 2, 2), labels = expression(lambda, lambda))
Semi-straight curved edges (Coming in version 1.2.1)
curvePivot argument now provides a way to turn curved edges in a combination of three straigth edges with rounded corners:
qgraph(matrix(1, 2, 2), directed = TRUE, curvePivot = TRUE, layout = cbind(c(-1, 1), 0), curve = 4, curveAll = TRUE)
The next plot shows some additional features:
qgraph(cbind(c(1, 1, 1, 2), c(2, 2, 2, 1), 1:4), bg = "black", curve = 3, edge.labels = TRUE)
Because the background color is dark, the edge border and labels are colored white by default. In addition, multiple edges between two nodes are now all curved uniquely. And finally, the edge label is now colored the same as the edge, with a small box surrounding it in the color of the background to improve readability.