get_net_cooccur_igraph: Retrieve an igraph co-occurrence network for a play

View source: R/net.R

get_net_cooccur_igraphR Documentation

Retrieve an igraph co-occurrence network for a play

Description

get_net_cooccur_igraph() returns a play network, given play and corpus names. Play network is constructed based on characters' co-occurrence matrix. Each node (vertex) is a character (circle) or a group of characters (square), edges width is proportional to the number of common play segments where two characters occur together.

Usage

get_net_cooccur_igraph(play = NULL, corpus = NULL, as_igraph = FALSE)

## S3 method for class 'cooccur_igraph'
plot(
  x,
  layout = igraph::layout_with_kk,
  vertex.label = label_cooccur_igraph(x),
  gender_colors = c(MALE = "#0073C2", FEMALE = "#EFC000", UNKNOWN = "#99979D"),
  vertex_size_metric = c("numOfWords", "numOfScenes", "numOfSpeechActs", "degree",
    "weightedDegree", "closeness", "betweenness", "eigenvector"),
  vertex_size_scale = c(5, 20),
  edge_size_scale = c(0.5, 4),
  vertex_label_adjust = TRUE,
  vertex.label.color = "#03070f",
  vertex.label.family = "sans",
  vertex.label.font = 2L,
  vertex.frame.color = "white",
  ...
)

## S3 method for class 'cooccur_igraph'
summary(object, ...)

Arguments

play

Character, name of a play (you can find all play names in "playName" column within an object returned by get_dracor). Character vector (longer than 1) is not supported.

corpus

Character, name of the corpus (you can find all corpus names in name column within an object returned by get_dracor_meta).

as_igraph

Logical, if TRUE, returns simple igraph object instead of cooccur_igraph. FALSE by default.

x

A cooccur_igraph object to plot.

layout

Function, an algorithm used for the graph layout. See igraph.plotting.

vertex.label

Character vector of character names. By default, function label_cooccur_igraph is used to avoid overplotting on large graphs.

gender_colors

Named character vector with 3 colors for the sex of characters (MALE, FEMALE and UNKNOWN, as returned by 'DraCor' API), e.g. the default c(MALE = "#0073C2", FEMALE = "#EFC000", UNKNOWN = "#99979D"). Any R color specification can be used, the order of the elements does not matter. Set NULL to use the default igraph colors. If you set parameter vertex.color (see igraph.plotting), gender_colors will be ignored.

vertex_size_metric

Character value, one of "numOfWords", "numOfScenes", "numOfSpeechActs", "degree", "weightedDegree", "closeness", "betweenness", "eigenvector" that will be used as a metric for vertex size. Alternatively, you can specify vertex size by yourself using parameter vertex.size(see igraph.plotting), in this case parameter vertex_size_metric is ignored.

vertex_size_scale

Numeric vector with two values. The first number is the size of the smallest vertex, the second one defines how much bigger the other vertices are: the size of a vertex is first + second * (metric - min(metric)) / max(metric) (all vertices get the first value if the metric is 0 for all of them). If you specify vertex size by yourself using parameter vertex.size(see igraph.plotting), vertex_size_scale is ignored.

edge_size_scale

Numeric vector with two values. The first number is the width of the thinnest edge, the second one defines how much thicker the other edges are: the width of an edge is first + second * (weight - min(weight)) / max(weight). Set NULL to use the default igraph edge width. If you specify edges width by yourself using parameter edge.width(see igraph.plotting), edge_size_scale is ignored.

vertex_label_adjust

Logical. If TRUE, labels positions are moved to the top of the respectives nodes. If FALSE, labels are placed in the nodes centers. TRUE by default. If you set parameter vertex.label.dist(see igraph.plotting) by yourself, vertex_label_adjust is ignored.

vertex.label.color

See igraph.plotting.

vertex.label.family

See igraph.plotting.

vertex.label.font

See igraph.plotting.

vertex.frame.color

See igraph.plotting.

...

Other arguments to be passed to plot.igraph

object

An object of class cooccur_igraph.

Value

cooccur_igraph — an object that inherits igraph and can be treated as such.

Functions

  • plot(cooccur_igraph): Plot cooccur_igraph using plot.igraph with slightly modified defaults.

  • summary(cooccur_igraph): Meaningful summary for "cooccur_igraph" object: network properties, sex distribution

See Also

get_net_relations_igraph label_cooccur_igraph

Examples



emilia_igraph <- get_net_cooccur_igraph(
  play = "lessing-emilia-galotti",
  corpus = "ger"
)
igraph::diameter(emilia_igraph)
plot(emilia_igraph)
plot(emilia_igraph,
  gender_colors = c(MALE = "steelblue", FEMALE = "tomato", UNKNOWN = "grey70")
)
summary(emilia_igraph)



rdracor documentation built on Oct. 22, 2026, 1:07 a.m.