0

I am trying to make a visual graph of a dissimilarity matrix. Using this site, I ran into the qgraph function from the package qgraph. Using the threshold flag, I am able to remove edges from my network above the supplied numerical value. This works beautifully, however, what if I only want to plot values below a certain threshold, not above?

For this, I came back to this site and read here: How to plot near-zero values with qgraph? to use the cut flag for this purpose. However, as the answer states, this flag will only "adjust the saturation so that everything above the cut point has the strongest color intensity, anything below the cut point, the saturation gets weaker."

What I would like to do is to plot only lines between the that are below my cut value (or threshold), not anything else.

Here is some reproducible data:

Dist <- data.frame(Sample_1 = c(0.0, 0.245, 0.191, 0.78, 0.5),  
               Sample_2 = c(0.3, 0.0, 0.2, 0.99, 0.6), 
               Sample_3 = c(0.65, 0.45, 0.0, 0.05, 0.8), 
               Sample_4 = c(0.45, 0.06, 0.88, 0.0, 0.7), 
               Sample_5 = c(0.11, 0.79, 0.66, 0.37, 0.0), 
              row.names = c("Sample_1", "Sample_2", "Sample_3", "Sample_4", "Sample_5"))

Plotting the graph:

qgraph(Dist, layout = "circle", vsize = 5, color = c("cyan", "yellow", "pink", "green3", "gray"), labels = c("Sample_1", "Sample_2", "Sample_3", "Sample_4", "Sample_5"), label.cex = 3, cut = 0.2)

As you can see, anything above the cut = 0.2 is also plotted and darker. enter image description here

I would like only values below the 0.2 threshold to be plotted. Is there any way to do this?

Thanks.

Community
  • 1
  • 1
Purrsia
  • 712
  • 5
  • 18

1 Answers1

1

qgraph does not seems to have the ability to cut below a threshold, so we have to manipulate the input data.

Replacing values above the threshold to 0 or NA should do it. Using NA result in the same output but with a warning.

Dist <- data.frame(
  Sample_1 = c(0.0, 0.245, 0.191, 0.78, 0.5),
  Sample_2 = c(0.3, 0.0, 0.2, 0.99, 0.6),
  Sample_3 = c(0.65, 0.45, 0.0, 0.05, 0.8),
  Sample_4 = c(0.45, 0.06, 0.88, 0.0, 0.7),
  Sample_5 = c(0.11, 0.79, 0.66, 0.37, 0.0),
  row.names = c("Sample_1", "Sample_2", "Sample_3", "Sample_4", "Sample_5")
)

library(qgraph)

qgraph(
  replace(Dist, Dist > 0.2, 0),
  layout = "circle",
  vsize = 5,
  color = c("cyan", "yellow", "pink", "green3", "gray"),
  labels = c("Sample_1", "Sample_2", "Sample_3", "Sample_4", "Sample_5"),
  label.cex = 3
)

Created on 2020-04-06 by the reprex package (v0.3.0)

GGamba
  • 13,140
  • 3
  • 38
  • 47
  • I may be reading the OP's question wrong, but don't they want to plot *only* low values and not suppress them? – Ian Campbell Apr 04 '20 at 21:37
  • GGamba: Thank you very much for suggesting `minimum` flag. I did try this beforehand and it still gives me all of those extra lines (the darker lines are just values above 0.2), so the outcome of using this flag is pretty much identical to the graph I posted. Because my real data-set is 110 columns by 100 columns, I need to see only lines between the nodes if the value is below 0.2. However, I truly appreciate your reply. – Purrsia Apr 04 '20 at 23:55
  • Sorry, not sure how I read it wrong. Will update the answer with a real answer – GGamba Apr 06 '20 at 07:13
  • Thank you very much! This worked beautifully. Also, thank you for introducing me to the `replace` function. – Purrsia Apr 06 '20 at 15:19