Contents
New features in qgraph 1.2.2
Curvature fix
In qgraph version 1.2 the way curved edges where drawn was changed. The curve
argument could now be used to directly specify the offset of the midpoint of the edge if it had been straigth to the midpoint of the edge when curved. While this is very useful in drawing path diagrams it resulted in too much curvature for edges between nodes that are closeby and too little curvature for edges in nodes that are far away.
In 1.2.2 the curveScale
argument has been added, defaulting to TRUE
, which controls if the curve should be scaled to the distance between nodes. This results in much more stable graphs. The 1.2 behavior can still be obtained by setting curveScale = FALSE
. For example.
# Dummy dataset:
mat <- matrix(1, 4, 4)
L <- c(1, 2, 4, 8)
L <- cbind(L, L)
layout(t(1:2))
# Old behavior (left):
qgraph(mat, layout = L, directed = TRUE, curveScale = FALSE)
# New behavior (right):
qgraph(mat, layout = L, directed = TRUE)
Legend of node names
Node names can now be assinged using the nodeNames
argument. This can be used to create a legend mapping node labels to node names. Note that this legend currently does not work in combination with the groups
argument.
set.seed(2)
Mat <- matrix(rnorm(4^2), 4, 4)
Labels <- LETTERS[1:4]
Names <- c("A much longer name", "Something else", "Also a node", "Nothing really")
qgraph(Mat, labels = Labels, nodeNames = Names)
Grid layout
A matrix with node labels can now be used to specify the layout, using a matrix that indicates the grid on which nodes are plotted. For example:
mat <- matrix(1, 4, 4)
Labels <- LETTERS[1:4]
Layout <- matrix(c(NA, "B", NA, "D", "A", NA, "C", NA), 2, byrow = TRUE)
Layout
## [,1] [,2] [,3] [,4]
## [1,] NA "B" NA "D"
## [2,] "A" NA "C" NA
qgraph(mat, layout = Layout, labels = Labels)
Pastel colors
The default rainbow colors can now be replaced by more calming pastel colors using the pastel
argument:
### BIG 5 DATASET ### Load big5 dataset:
data(big5)
data(big5groups)
# Correlations:
Q <- qgraph(cor(big5), minimum = 0.25, cut = 0.4, vsize = 1.5, groups = big5groups,
legend = FALSE, borders = FALSE, pastel = TRUE)
More node shapes
Node shapes can now also be rectangle
, ellipse
, heart
and star
. The vsize2
argument controls the height of these shapes. In addition, custom shapes can be added using the polygonList
argument.
set.seed(1)
Mat <- matrix(rnorm(4^2), 4, 4)
Shapes <- c("rectangle", "ellipse", "heart", "star")
Width <- c(10, 10, 8, 8)
Height <- c(5, 5, 8, 8)
qgraph(Mat, shape = Shapes, vsize = Width, vsize2 = Height)
Do note that these node shapes can significantly increase PDF file size over circle
and square
.
Bars inside nodes:
Bars can now be added inside nodes. The main functionality of this is by portraying thresholds in semPlot. Note that this is not intended to be used as shading lines. See qgraph
help page on the argument bars
and other arguments controlling the bars.
Mat <- matrix(1, 2, 2)
qgraph(Mat, bars = list(NULL, c(0.2, 0.5, 0.9)), vsize = 20, shape = "square")
Internal changes
A change has been made to the qgraph internal repressentation. First, qgraph
computed quite some parameters for the graph, then used them to plot and finally created an output model containing the arguments that allowed the plot to be plotted again. Now, qgraph
creates a model, and plot.qgraph
plots it (by default, plot.qgraph
is now called at the end of qgraph
). Because of this, every aspect of a graph can now be manually changed between running qgraph
and plotting the output (use DoNotPlot
to ignore plotting the first run).
For users specifically the graphAttributes
element of the output is important. Future versions of qgraph
will contain functions to more easilly edit these attributes.
Mat <- matrix(1, 2, 2)
Graph <- qgraph(Mat, DoNotPlot = TRUE)
str(Graph)
## List of 6
## $ Edgelist :List of 5
## ..$ from : int 1
## ..$ to : int 2
## ..$ weight : num 1
## ..$ directed : logi FALSE
## ..$ bidirectional: logi FALSE
## $ Arguments :List of 1
## ..$ DoNotPlot: logi TRUE
## $ plotOptions :List of 40
## ..$ filetype : chr "default"
## ..$ filename : chr "qgraph"
## ..$ background : chr "#FFFFFF"
## ..$ bg : logi FALSE
## ..$ normalize : logi TRUE
## ..$ plot : logi TRUE
## ..$ mar : num [1:4] 0.3 0.3 0.3 0.3
## ..$ GLratio : num 2.5
## ..$ legend : logi FALSE
## ..$ legend.cex : num 0.6
## ..$ pty : chr "m"
## ..$ XKCD : logi FALSE
## ..$ residuals : logi FALSE
## ..$ residScale : num 1
## ..$ arrows : logi TRUE
## ..$ arrowAngle : num 0.393
## ..$ open : logi FALSE
## ..$ curvePivot : logi FALSE
## ..$ curveShape : num -1
## ..$ curveScale : logi TRUE
## ..$ curvePivotShape: num 0.25
## ..$ label.scale : logi TRUE
## ..$ label.prop : num 0.9
## ..$ label.norm : chr "OOO"
## ..$ overlay : logi FALSE
## ..$ details : logi FALSE
## ..$ legend.mode : chr "groups"
## ..$ srt : num [1, 1:4] 1 2 0 1
## .. ..- attr(*, "dimnames")=List of 2
## .. .. ..$ : NULL
## .. .. ..$ : chr [1:4] "" "" "knots" ""
## ..$ gray : logi FALSE
## ..$ overlaySize : num 0.5
## ..$ plotELBG : logi TRUE
## ..$ alpha : num [1:4] 1e-04 1e-03 1e-02 5e-02
## ..$ width : num 7
## ..$ height : num 7
## ..$ aspect : logi FALSE
## ..$ rescale : logi TRUE
## ..$ barsAtSide : logi FALSE
## ..$ bgres : num 100
## ..$ bgcontrol : num 6
## ..$ resolution : num 320
## $ graphAttributes:List of 4
## ..$ Nodes:List of 15
## .. ..$ border.color: chr [1:2] "black" "black"
## .. ..$ borders : logi TRUE
## .. ..$ border.width: num 1
## .. ..$ label.color : chr "black"
## .. ..$ labels : logi TRUE
## .. ..$ names : logi TRUE
## .. ..$ loopRotation: num [1:2] 5.44 2.3
## .. ..$ shape : chr [1:2] "circle" "circle"
## .. ..$ color : chr [1:2] "#FFFFFF" "#FFFFFF"
## .. ..$ width : num [1:2] 5.32 5.32
## .. ..$ height : num [1:2] 5.32 5.32
## .. ..$ bars :List of 2
## .. .. ..$ : NULL
## .. .. ..$ : NULL
## .. ..$ barSide : num [1:2] 1 1
## .. ..$ barColor : chr [1:2] "black" "black"
## .. ..$ barLength : num [1:2] 0.5 0.5
## ..$ Edges:List of 11
## .. ..$ curve : num 0
## .. ..$ color : chr "#808080FF"
## .. ..$ labels : logi FALSE
## .. ..$ label.cex : num 1
## .. ..$ label.bg : chr "#FFFFFF"
## .. ..$ font : num 1
## .. ..$ width : num 2
## .. ..$ lty : num 1
## .. ..$ residEdge : logi FALSE
## .. ..$ CircleEdgeEnd: logi FALSE
## .. ..$ asize : num 3
## ..$ Graph:List of 10
## .. ..$ nNodes : int 2
## .. ..$ weighted : logi FALSE
## .. ..$ edgesort : int 1
## .. ..$ groups :List of 1
## .. .. ..$ : int [1:2] 1 2
## .. ..$ minimum : num 0
## .. ..$ maximum : num 1
## .. ..$ cut : num 0
## .. ..$ polygonList:List of 3
## .. .. ..$ ellipse:List of 2
## .. .. .. ..$ x: num [1:200] 0 0.0316 0.0631 0.0946 0.126 ...
## .. .. .. ..$ y: num [1:200] 1 1 0.998 0.996 0.992 ...
## .. .. ..$ heart :List of 2
## .. .. .. ..$ x: num [1:63] 0.000525 0.00152 0.008372 0.026353 0.059623 ...
## .. .. .. ..$ y: num [1:63] 0.521 0.535 0.575 0.638 0.714 ...
## .. .. ..$ star :List of 2
## .. .. .. ..$ x: num [1:200] 0 0.013 0.026 0.039 0.052 ...
## .. .. .. ..$ y: num [1:200] 1 0.961 0.921 0.882 0.843 ...
## .. ..$ mode : chr "strength"
## .. ..$ color : chr "background"
## ..$ Knots:List of 6
## .. ..$ knots : num 0
## .. ..$ knot.size : num 1
## .. ..$ knot.color : logi NA
## .. ..$ knot.borders : logi FALSE
## .. ..$ knot.border.color: chr "black"
## .. ..$ knot.border.width: num 1
## $ layout : num [1:2, 1:2] -1 1 1 -1
## $ layout.orig : num [1:2, 1:2] 2.21e-17 1.00e-16 6.39e-01 -6.39e-01
## - attr(*, "class")= chr "qgraph"