1

I would like to create a single figure with multiple panels, in which each panel contains a qgraph network plot.

Ideally, I would do this:

pacman::p_load(qgraph)

# Load big5 dataset:
data(big5)
data(big5groups)

# Correlations:
Q <- qgraph(cor(big5), minimum = 0.25, cut = 0.4, vsize = 1.5, groups = big5groups, 
            legend = TRUE, borders = FALSE)
title("Big 5 correlations", line = 2.5)

# Same graph with spring layout:
Q2 <- qgraph(Q, layout = "spring")
title("Big 5 correlations spring", line = 2.5)

cowplot::plot_grid(Q, Q2)

But this won't work, because cowplot doesn't know how to convert the qgraph objects to grobs.

I have tried converting the qgraph objects to igraph objects, which I think I should be able to further convert to grobs, perhaps using tidygraph, ggraph, GGally, ggnetwork, or similar, but some of the information I would like to convey is lost along the way, and I already have my networks plotted just the way I want using qgraph.

It seems that there has previously been an experimental as.ggraphfunction in qgraph that might have helped, but it appears that no longer exists.

My question is: Is there any way to either simply convert qgraph objects to grobs, or otherwise produce an image with several qgraph objects next to each other?

ethanweed
  • 33
  • 7
  • Still looking for a solution to this. It seems like it shouldn't be too hard, because I believe `qgraph` actually uses `ggplot2` under the hood to build its figures. So far, my workaround has been to export the figures as image files, and then read them back in and use `cowplot::draw_image()` together with `cowplot:::plot_grid()` to arrange them. It works, but still isn't quite what I'd like. – ethanweed Apr 12 '22 at 19:40
  • I'll come back and post a proper answer later, but for now I'll just point to [my own solution](https://github.com/ethanweed/qgraph2ggplot) which may not be pretty, but does what I need. – ethanweed Sep 01 '22 at 12:18

1 Answers1

1

I think you can do this:

par(mfrow=c(1, 2))

qgraph(cor(big5), minimum = 0.25, cut = 0.4, vsize = 1.5, groups = big5groups, legend = TRUE, borders = FALSE)

qgraph(Q, layout = "spring")
Martin Gal
  • 16,640
  • 5
  • 21
  • 39
  • Thanks for taking the time to post this! I hadn't thought of using `par()`. This solution does make a multiplot figure, but I would still like to actually convert the qgraph objects into grobs so that I can do other manipulations with them. – ethanweed Apr 12 '22 at 19:29
  • I always use the `layout()` function in R. The `qgraph` package just creates base R figures so this question would be the same for any base R figure. Easiest perhaps is to just load it as a PNG into R... – Sacha Epskamp Jan 11 '23 at 02:06