plot_word_network: Plot Word Network

Description Usage Arguments Value Examples

View source: R/word_network.R

Description

Plots a word network of adjacent words.

Usage

 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
plot_word_network(
  input,
  model = NULL,
  topX = 100,
  graphIndividual = TRUE,
  graphCombined = FALSE,
  directed = FALSE,
  removeVerticesBelowDegree = 2,
  clusterType = "none",
  clusterNodeMethod = "infomap",
  plotUnclusteredNetwork = TRUE,
  plotClusteredNetwork = TRUE,
  plotIndividualClusters = TRUE,
  plotIndividualClusterFacet = TRUE,
  plotClusterLegend = TRUE,
  plotNodeColors = TRUE,
  edgeColor = "darkgray",
  edgeAlpha = 0.5,
  edgeCurve = 0.15,
  modelNodeColors = c("lightblue", "orange"),
  modelNodeSizeRange = c(5, 10),
  nodeLabelSize = 1,
  nodeLabelColor = "black",
  plotTitle = NULL,
  layout = NULL
)

Arguments

input

An input dataframe, typically the output from the node_edge function

model

Optional - if node_edge used a model as input, the same model can be provided here for extra functionality

topX

The number of word pairs to include in the graphed network. Chosen word pairs are selected from those with the greatest number of co-occurrences. Defaults to 100. If NULL, all pairs will be used.

graphIndividual

If TRUE, individual graphs are produced for both outcomes of the model. Default is TRUE.

graphCombined

If TRUE, a network is graphed based on the entire language corpus. Default is FALSE.

directed

Determines if the network is directed (direction of edges matters) or not. Defaults to FALSE (the output from node_edge does not yield directional edge information, so only change this if using your own dataframe).

removeVerticesBelowDegree

An integer which determines the minimum number of edges a node must have to be included. Default is 2.

clusterType

The type of clustering to perform. "node" clusters by nodes (using the method defined by clusterNodeMethod), "edge" clusters by edges (using the lincomm package. Defaults to "none".

clusterNodeMethod

If clustering by "node", this determines the method used. Options are the same clustering options given in the igraph package.

plotUnclusteredNetwork

If TRUE, the network is plotted with no clustering displayed. Defaults to TRUE.

plotClusteredNetwork

If TRUE, the network is plotted with clustering displayed (shaded regions for "node" clustering, colored edges for "edge" clustering). Defaults to TRUE.

plotIndividualClusters

If TRUE, each cluster is plotted in a separate graph. Defaults to TRUE.

plotIndividualClusterFacet

If TRUE, each cluster is plotted in a faceted section of a single graph. Defaults to TRUE.

plotClusterLegend

If TRUE, plots a legend with cluster numbers and corresponding colors. Defaults to TRUE.

plotNodeColors

If TRUE, nodes are colored in based on the model provided.

edgeColor

The color of the edges. Default is "darkgray".

edgeAlpha

The alpha of the edges. Default is 0.5.

edgeCurve

If greater than 0, edges will be curved with a radius corresponding to the value. Default is 0.15. A value of 0 yields straight edges.

modelNodeColors

The color shading for nodes that are predictive words in the provided model. Must be a vector of two values. Defaults to c("lightblue", "orange").

modelNodeSizeRange

The sizing for nodes that are predictive words in the provided model. Must be a vector of two values (the minimum plotted size and maximum plotted size). Defaults to c(5, 10).

nodeLabelSize

The size of the text for node labels. Defaults to 1.

nodeLabelColor

The color of the node labels. Defaults to "black".

plotTitle

The title of the plot(s). If a model is used, it must be a vector of three strings. If not, it must be a single string.

layout

An igraph layout object, helpful if you want to re-graph the same network multiple times with the same layout

Value

A list containing the igraph network object, igraph layout, and clustering data (if applicable) - this can be used with the plot_cluster function, or graphed manually with the igraph package

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
movie_review_data1$cleanText = clean_text(movie_review_data1$text)

# Using language to predict "Positive" vs. "Negative" reviews
movie_model_valence = language_model(movie_review_data1,
                                     outcomeVariableColumnName = "valence",
                                     outcomeVariableType = "binary",
                                     textColumnName = "cleanText")

node_edge_table = node_edge(movie_model_valence)
plot_word_network(node_edge_table)

## End(Not run)

nlanderson9/languagePredictR documentation built on June 10, 2021, 11 a.m.