0% found this document useful (0 votes)
104 views

What Are Social Networks?: James Curley

This document provides an introduction to network analysis in R. It discusses what social networks are, how to represent network data using adjacency matrices and edgelists, and how to use the igraph package to analyze networks. It demonstrates how to create igraph objects, add vertex and edge attributes, subset networks, and visualize networks using different layouts. The goal is to teach the basics of network analysis and visualization in R.

Uploaded by

naiveangulo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

What Are Social Networks?: James Curley

This document provides an introduction to network analysis in R. It discusses what social networks are, how to represent network data using adjacency matrices and edgelists, and how to use the igraph package to analyze networks. It demonstrates how to create igraph objects, add vertex and edge attributes, subset networks, and visualize networks using different layouts. The goal is to teach the basics of network analysis and visualization in R.

Uploaded by

naiveangulo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

DataCamp Network

Analysis in R

NETWORK ANALYSIS IN R

What are social


networks?

James Curley
Associate Professor,
University of Texas at Austin
DataCamp Network Analysis in R

What are Social Networks?


DataCamp Network Analysis in R

Network Data: Adjacency Matrix


DataCamp Network Analysis in R

Network Data: Edgelist


DataCamp Network Analysis in R

The igraph R package


library(igraph)

g <- graph.edgelist(as.matrix(df),
directed = FALSE)

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

igraph objects
V(g) plot(g)
+ 7/7 vertices, named:
[1] A B C D E F G

E(g)
+ 7/7 edges (vertex names):
[1] A--B A--C A--D A--E A--F E--F

gorder(g)
[1] 7

gsize(g)
[1] 7
DataCamp Network Analysis in R

NETWORK ANALYSIS IN R

Let's practice!
DataCamp Network Analysis in R

NETWORK ANALYSIS IN R

Network attributes

James Curley
Associate Professor,
University of Texas at Austin
DataCamp Network Analysis in R

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
DataCamp Network Analysis in R

Edge Attributes
DataCamp Network Analysis in R

Adding Attribtues I

Vertex Attributes Edge Attributes

g <- set_vertex_attr(g, "age", g <- set_edge_attr(g, "frequency",


value = c(20,25,21,23,24,23,22)) value = c(2,1,1,1,3,2,4))

vertex_attr(g)
edge_attr(g)
$name
[1] "A" "B" "C" "D" "E" "F" "G" $frequency
[1] 2 1 1 1 3 2 4
$age
[1] 20 25 21 23 24 23 22
DataCamp Network Analysis in R

Adding attributes II

graph_from_data_frame(d = edges.df, vertices = vertices.df, directed = FALSE)


DataCamp 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
DataCamp Network Analysis in R

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

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


DataCamp Network Analysis in R

NETWORK ANALYSIS IN R

Let's practice!
DataCamp Network Analysis in R

NETWORK ANALYSIS IN R

Network Visualization

James Curley
Associate Professor,
University of Texas at Austin
DataCamp Network Analysis in R
DataCamp Network Analysis in R

Styling Vertices and Edges


DataCamp Network Analysis in R

Choosing the Appropriate Layout

Minimize edge crossing

Do not allow vertices to overlap

Make edge lengths as uniform as possible

Increase symmetry of the network as much as possible

Position more influential nodes towards the center


DataCamp Network Analysis in R

igraph Layouts

plot(g, layout = layout.fruchterman.reingold(g))


DataCamp Network Analysis in R

NETWORK ANALYSIS IN R

Let's practice!

You might also like