as.igraph.epicontacts: Create igraph object from contact data

Description Usage Arguments Value Author(s) Examples

View source: R/as.igraph.epicontacts.R

Description

This function creates an igraph object from a given epicontacts object containing a 'contacts' dataframe.

Usage

1
2
## S3 method for class 'epicontacts'
as.igraph(x)

Arguments

x

An epicontacts object.

Value

An igraph object (from the igraph package). Note: any column called "name" in the original linelist will be stored as a new vertex attribute in the igraph object named 'epicontacts_name'. This is due to the inherent behaviour of igraph creating its own 'name' vertex attribute.

Author(s)

Nistara Randhawa ([email protected])

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
if (require(outbreaks) && require(igraph)) {
## build data

x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts,
                      id = "case_id", to = "case_id", from ="infector",
                      directed = TRUE)


## subset data - keep 50 cases from linelist with contacts

ids <- get_id(x, "common")[1:50]
ids
x <- x[ids, ids]


## make igraph object with associated attributes from epicontacts object

net <- as.igraph(x)
net
plot(net, vertex.label = "", vertex.size = 10,
     vertex.color = cases_pal(50))
}

epicontacts documentation built on May 2, 2019, 11:29 a.m.