0

I am using qgraph package to plot network of correlations, which show both positive and negative values. I need a gray scale plot due to journal restrictions, so color of nodes can be easily set but I'm having difficulties with edges. I would like to set a different line type for positive ("solid") and negative ("dashed") correlations, so we don't need gray code for nodes and also for edges. The argument lty in ´qgraph`only allows for one type of line for the whole plot, how can I get it to work?

Here's a tentative solution

qgraph(polys$rho, groups = structure_hscl, 
         color= c("white","gray","gray25"),
         borders=TRUE, trans=FALSE, details=TRUE,
         bonf=TRUE, alpha=.05,
         normalize =TRUE, vsize=3, 
         threshold= .2, labels=labels_hscl,
         layout="spring", graph="pcor", 
         lty = c("solid","dashed")   # this obviously doesn't work )

Thanks a lot beforehand!

Gina Zetkin
  • 333
  • 1
  • 5
  • 12

1 Answers1

0

It seems that lty needs to be a vector of suitable values. So how do we know which edges should be dashed and which solid? I'll demonstrate one way to get the job done using the bfi data from the psych package.

library(psych)
library(qgraph)
data(bfi)

persvars <- bfi[,1:25]

Let's then create a temporary graph and infer which lines to draw as dashed based on the colors:

hackgraph <- qgraph(cor(persvars,use = "pa"), fade = FALSE, layout = "spring", graph = "pcor")

edgecolor <- hackgraph$graphAttributes$Edges$color
unique(hackgraph$graphAttributes$Edges$color)

Setting fade = FALSE above reduced the colors to a manageable number: now we know that positive edges are either "#009900" or "darkgreen" in color. So all we need to do is to form a new vector as:

linetype <- ifelse( (edgecolor == "#009900" | edgecolor =="darkgreen"), 1, 2)

We can then draw the desired graph based on these line types:

qgraph(cor(persvars,use = "pa"), layout = "spring", graph = "pcor", lty = linetype) 

Graph with negative edges as dashed lines

RBT
  • 24,161
  • 21
  • 159
  • 240