This function creates a co-occurrence matrix based on one or more coded sources. Optionally, it plots a heatmap, simply by calling the stats::heatmap() function on that matrix.

create_cooccurrence_matrix(
  x,
  codes = x$convenience$codingLeaves,
  plotHeatmap = FALSE
)

Arguments

x

The parsed source(s) as provided by rock::parse_source or rock::parse_sources.

codes

The codes to include; by default, takes all codes.

plotHeatmap

Whether to plot the heatmap.

Value

The co-occurrence matrix; a matrix.

Examples

### Get path to example source
examplePath <-
  system.file("extdata", package="rock");

### Parse a selection of example sources in that directory
parsedExamples <-
  rock::parse_sources(
    examplePath,
    regex = "(test|example)(.txt|.rock)"
  );

### Create cooccurrence matrix
rock::create_cooccurrence_matrix(parsedExamples);
#>                   Topic1 Topic2 att_ins_eval chairs down google inducChild1
#> Topic1                 1      0            0      0    0      0           0
#> Topic2                 0      1            0      0    0      0           0
#> att_ins_eval           0      0            1      0    0      0           0
#> chairs                 0      0            0      1    0      0           0
#> down                   0      0            0      0    2      0           0
#> google                 0      0            0      0    0      1           0
#> inducChild1            0      0            0      0    0      0           3
#> inducChild2            0      0            0      0    0      0           0
#> inducChild3            0      0            0      0    0      0           0
#> inducChild4            0      0            0      0    0      0           1
#> inducChild5            0      0            0      0    0      0           0
#> internet               0      0            0      1    0      0           0
#> oaken_chests           0      0            0      0    0      0           0
#> people                 0      0            0      0    0      0           0
#> process_query          0      0            0      0    0      0           0
#> search_engine_hit      0      0            0      0    0      0           0
#> tables                 0      0            1      0    0      0           0
#> typing                 0      0            0      0    0      0           0
#>                   inducChild2 inducChild3 inducChild4 inducChild5 internet
#> Topic1                      0           0           0           0        0
#> Topic2                      0           0           0           0        0
#> att_ins_eval                0           0           0           0        0
#> chairs                      0           0           0           0        1
#> down                        0           0           0           0        0
#> google                      0           0           0           0        0
#> inducChild1                 0           0           1           0        0
#> inducChild2                 1           0           0           0        0
#> inducChild3                 0           4           0           0        0
#> inducChild4                 0           0           3           0        0
#> inducChild5                 0           0           0           1        0
#> internet                    0           0           0           0        2
#> oaken_chests                0           0           0           0        0
#> people                      0           0           0           0        0
#> process_query               0           0           0           0        0
#> search_engine_hit           0           0           0           0        0
#> tables                      0           0           0           0        0
#> typing                      0           0           0           0        0
#>                   oaken_chests people process_query search_engine_hit tables
#> Topic1                       0      0             0                 0      0
#> Topic2                       0      0             0                 0      0
#> att_ins_eval                 0      0             0                 0      1
#> chairs                       0      0             0                 0      0
#> down                         0      0             0                 0      0
#> google                       0      0             0                 0      0
#> inducChild1                  0      0             0                 0      0
#> inducChild2                  0      0             0                 0      0
#> inducChild3                  0      0             0                 0      0
#> inducChild4                  0      0             0                 0      0
#> inducChild5                  0      0             0                 0      0
#> internet                     0      0             0                 0      0
#> oaken_chests                 1      1             0                 0      0
#> people                       1      3             0                 0      1
#> process_query                0      0             1                 0      0
#> search_engine_hit            0      0             0                 1      0
#> tables                       0      1             0                 0      2
#> typing                       0      0             0                 0      0
#>                   typing
#> Topic1                 0
#> Topic2                 0
#> att_ins_eval           0
#> chairs                 0
#> down                   0
#> google                 0
#> inducChild1            0
#> inducChild2            0
#> inducChild3            0
#> inducChild4            0
#> inducChild5            0
#> internet               0
#> oaken_chests           0
#> people                 0
#> process_query          0
#> search_engine_hit      0
#> tables                 0
#> typing                 1