Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, I am using <code>GGally::ggnet</code> as this is available through CRAN. I believe this is equivalent to that on github.</p> <pre><code>library(network) library(GGally) library(ggplot2) # dependencies library(grid) library(sna) library(intergraph) </code></pre> <p>The reason you have many unconnected nodes in your network diagram is because the node names you have supplied are not an unbroken sequence of integers. For example, if you supply only an edge between nodes named <code>1</code> and <code>10</code>, <code>network()</code> will assume the presence of eight unconnected nodes with names <code>2:9</code>. For example,</p> <pre><code>netwk1 &lt;- network(cbind(1,2), directed = F) get.vertex.attribute(netwk1, attrname="vertex.names") netwk2 &lt;- network(cbind(1,10), directed = F) get.vertex.attribute(netwk2, attrname="vertex.names") </code></pre> <p>So if you convert your node names to an unbroken sequence, you will lose all the unconnected nodes. So something like:</p> <pre><code>df2[,1:2]=as.numeric(as.factor(df2[,c(1,2)])) net &lt;- network(df2[,c(1,2)], directed = F) ggnet(net, mode = 'kamadakawai', size = 6, alpha = .5, label.nodes=T, segment.alpha = 0.5, color = "black") + theme(legend.position = "none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "cm")) </code></pre> <p>You can color the edges with the <code>segment.color</code> argument in <code>ggnet()</code> :</p> <pre><code>edge_color = ifelse(df2[,3]==-1, "red", "green") ggnet(net, mode = 'kamadakawai', size = 6, alpha = .5, segment.color=edge_color, label.nodes=T, segment.alpha = 0.5, color = "black") + theme(legend.position = "none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "cm")) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload