Network Attributes

Network Analysis in R

James Curley

Associate Professor, University of Texas at Austin

Vertex attributes

g
IGRAPH UN-- 7 7 -- 
+ attr: name (v/c)
+ edges (vertex names):
[1] A--B A--C A--D A--E A--F E--F F--G
Network Analysis in R

Edge attributes

Network Analysis in R

Adding Vertex Attributes

g <- set_vertex_attr(
  g, 
  "age", 
  value = c(
    20,25,21,23,24,23,22
    )
  )

vertex_attr(g)
$name
[1] "A" "B" "C" "D" "E" "F" "G"

$age
[1] 20 25 21 23 24 23 22

Adding Edge Attributes

g <- set_edge_attr(
  g, 
  "frequency", 
  value = c(
    2,1,1,1,3,2,4
    )
  )

edge_attr(g)
$frequency
[1] 2 1 1 1 3 2 4
Network Analysis in R

Adding attributes II

graph_from_data_frame(d = edges.df, vertices = vertices.df, 
                      directed = FALSE)
Network Analysis in R

Subsetting networks

E(g)[[.inc('E')]]
+ 2/7 edges (vertex names):
  tail head tid hid frequency
4    E    A   5   1         1
6    F    E   6   5         2
E(g)[[frequency>=3]]
+ 2/7 edges (vertex names):
  tail head tid hid frequency
5    F    A   6   1         3
7    G    F   7   6         4
Network Analysis in R

Network visualization

V(g)$color <- ifelse(
  V(g)$age > 22, "red", "white"
)

plot(
  g, 
  vertex.label.color = "black"
)

Network Analysis in R

Let's practice!

Network Analysis in R

Preparing Video For Download...