frequent_terms_co_occurrence: Plot Co-Occurrence of Frequent Terms

Description Usage Arguments Value Examples

View source: R/frequent_terms_co_occurrence.R

Description

Generate a tag_co_occurrence object from frquent terms.

Usage

1

Arguments

x

A vector of character strings.

bound

logical. If TRUE each side of the frequent term is wrapped with a word boundary before performing thre regex search. Otherwise, the search is fuzzy matched.

...

Other arguments passed to frequent_terms.

Value

Returns a tag_co_occurrence object from frequent terms.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
## Not run: 
frequent_terms_co_occurrence(presidential_debates_2012[["dialogue"]])
frequent_terms_co_occurrence(presidential_debates_2012[["dialogue"]], bound = FALSE)

x <- frequent_terms_co_occurrence(presidential_debates_2012[["dialogue"]], n=50)
x
plot(x, min.edge.cutoff = .1, node.color = "gold")
plot(x, min.edge.cutoff = .075, node.color = "#1CDB4F")

## Load Required Add-on Packages
if (!require("pacman")) install.packages("pacman")
pacman::p_load(igraph, qrage)
pacman::p_load_gh("mattflor/chorddiag", "trinker/textshape")

## Matrix Manipulation Function
remove_diags <- function(mat, rm.lower = FALSE, order = TRUE, ...) {
    diag(mat) <- 0
    if (isTRUE(rm.lower)) mat[lower.tri(mat)] <- 0
    if (order) {
        ord <- order(rowSums(mat))
        mat <- mat[ord, ord]
    }
    mat
}

##--------------
## Chord Diagram
##--------------
chorddiag::chorddiag(
    remove_diags(x[["adjacency"]]),
    margin = 150,
    showTicks =FALSE,
    groupnamePadding = 5,
    groupThickness = .05,
    chordedgeColor = NA
)

add_diags <- function(x, y, ...){
    diag(x) <- y
    x
}

order_tags <- function(x, ...){
    ord <- order(rowSums(x))
    x[ord, ord]
}

remove_lower <- function(x, ...){
    x[lower.tri(x)] <- 0
    x
}


chorddiag::chorddiag(
    add_diags(x[["adjacency"]],x[["node_size"]])  %>% order_tags() %>% remove_lower(),
    margin = 150,
    showTicks =FALSE,
    groupnamePadding = 5,
    groupThickness = .05,
    chordedgeColor = NA
)

chorddiag::chorddiag(
    x[["adjacency"]] %>% order_tags() %>% remove_lower(),
    margin = 150,
    showTicks =FALSE,
    groupnamePadding = 5,
    groupThickness = .05,
    chordedgeColor = NA
)

##--------------
## Network Graph
##--------------
graph <- igraph::graph.adjacency(
    remove_diags(x[["adjacency"]], order=FALSE),
    weighted = TRUE
)

linkdf <- stats::setNames(get.data.frame(graph), c("source", "target", "value"))

qrage::qrage(
    links = linkdf,
    nodeValue = textshape::tidy_vector(x[['node_size']]),
    cut = 0.1
)

## End(Not run)

trinker/termco documentation built on Jan. 7, 2022, 3:32 a.m.