Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 1.32 KB

index.md

File metadata and controls

71 lines (51 loc) · 1.32 KB
library(netplot)
Loading required package: grid
library(igraph)
Attaching package: 'igraph'

The following object is masked from 'package:netplot':

    ego

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union
library(data.table)
library(rgexf)

edgelist <- fread("edgelist.csv")
vertices <- fread("vertices.csv")

# Checking which edgelist vertex is not in the list of vertices
vnames_in_edgelist <- edgelist[,c(source, target)]
vnames_in_edgelist[
  which(!vnames_in_edgelist %in% vertices[, name])
]
character(0)
net <- graph_from_data_frame(edgelist, directed = FALSE, vertices = vertices) 
set.seed(331)
np <- nplot(
  net,
  vertex.color = ~type,
  vertex.size.range = c(.015, .02),
  edge.color = ~ego + alter,
  edge.curvature = pi/6,
  vertex.label.show = 1
  )

V(net)$color <- get_vertex_gpar(np, "core", "col")$col
E(net)$color <- get_edge_gpar(np, "line", "col")$col[1,]
np

# Saving the gexf object
pos <- cbind(np$.layout, 0)
colnames(pos) <- c("x", "y", "z")
net_gexf <- igraph.to.gexf(net, nodesVizAtt = list(position = pos))
plot(net_gexf, dir = "docs", nodeSizeFactor = .5)