Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node labels overlapping #5

Closed
andrewjohnlowe opened this issue Nov 11, 2016 · 3 comments
Closed

Node labels overlapping #5

andrewjohnlowe opened this issue Nov 11, 2016 · 3 comments

Comments

@andrewjohnlowe
Copy link

Hi Sacha,

I'm a big fan of qgraph; I think it's great! It's been very useful for my particle physics data analysis, where I use it to study correlations between feature variables in my models.

But I have a problem with overlapping node labels with large force-directed networks (layout = "spring"). This happens when I have a lot of very highly-correlated features clustering together tightly. It's not possible to read the node labels. I could use abbreviated node labels or number the nodes and use a legend, but often this doesn't help, and it makes it harder to read the information contained in the visualisation.

I've been trying to develop a fix for this myself, but without much luck. I have tried to convert the qgraph object to an igraph object using as.igraph(), but the resultant igraph network doesn't look much like the qgraph network. They seem very different in their topology. It's possible that I just don't understand igraph well enough to use it effectively. My plan would then be to use ggnetwork to convert the igraph object into something that ggplot2 will understand, and use ggrepel for the node labels. This is kind of what I had in mind:
https://rud.is/projects/clinton_emails_01.html
See? No overlapping node labels! But, sadly, I haven't been able to do this. The networks from igraph and qgraph are very very different, and I've failed in my attempts to use ggnetwork to produce anything even remotely resembling the network that qgraph produced. My second idea was to parse the qgraph object for edge and node information, and although I can see how to use ggplot2 to get the node positions, I don't know how to proceed to get the node labels and edges.

Basically, I'd like either qgraph to support ggrepel for node labels, or I'd like to do:
qgraph(matrix) --> igraph object --> ggnetwork --> ggplot2 plot + ggrepel for node labels.

Any ideas on how either of these two options could be implemented?

With many thanks,

Andrew.

@SachaEpskamp
Copy link
Owner

Hi Andrew,

Thank you for your message. Unfortunately I have not yet looked well enough at ggnetwork to see how the conversion would work, although this is certainly something I plan to do! One thing I like to do is to construct a HTML file with mouseover tooltips. Perhaps that can be of use to you?


library("qgraph")

### Using bfi dataset from psych ###
library("psych")
data(bfi)

# Compute correlations:
CorMat <- cor_auto(bfi[,1:25])

# Compute graph with tuning = 0 (BIC):
BICgraph <- qgraph(CorMat, graph = "glasso", sampleSize = nrow(bfi),
                   tuning = 0, layout = "spring", title = "BIC", details = TRUE)

Names <- scan("http://sachaepskamp.com/files/BFIitems.txt",what = "character", sep = "\n")

qgraphAnnotate(BICgraph,fromqgraph=FALSE,Item = Names)

@andrewjohnlowe
Copy link
Author

Hi Sacha,

Thanks for your reply. Using mouseover tooltips is something I certainly planned to use for the HTML version of my journal paper, but for the print version I still need a way of making the node labels visible. I was also wondering where there was a way to make the node shapes "solid"; i.e., define a minimum distances between nodes so that they can pack together and can touch but not overlap. This would ameliorate (at least partially) the problem of overlapping labels. I was wondering if there was a way to hack the repulsion between nodes that might enable this. This might be a workaround that doesn't involve other packages like ggplot2 or ggrepel. No idea how to implement it, though. What do you think?

Best regards,

Andrew

@SachaEpskamp
Copy link
Owner

Hi Andrew,

There is the "repulsion" argument you can play around with, which sets a parameter in the Fruchterman Reingold algorithm. Setting it lower than 1 makes nodes repulse each-other more.

Best, Sacha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants