
Analyze and Visualize Word Frequencies Across a Continuous Variable
Source:R/text_mining_functions.R
word_frequency_distribution.Rd
This function analyzes and visualizes word frequencies across a continuous variable.
Usage
word_frequency_distribution(
dfm_object,
continuous_variable,
selected_terms,
height = 500,
width = 900
)
Arguments
- dfm_object
A quanteda document-feature matrix (dfm).
- continuous_variable
A continuous variable in the metadata.
- selected_terms
A vector of terms to analyze trends for.
- height
The height of the resulting Plotly plot, in pixels (default: 500).
- width
The width of the resulting Plotly plot, in pixels (default: 900).
Details
This function requires a fitted STM model object and a quanteda dfm object. The continuous variable should be a column in the metadata of the dfm object. The selected terms should be a vector of terms to analyze trends for. The required packages are 'htmltools', 'splines', and 'broom' (plus additional ones loaded internally).
Examples
if (interactive()) {
df <- TextAnalysisR::SpecialEduTech
united_tbl <- TextAnalysisR::unite_text_cols(df, listed_vars = c("title", "keyword", "abstract"))
tokens <- TextAnalysisR::preprocess_texts(united_tbl, text_field = "united_texts")
dfm_object <- quanteda::dfm(tokens)
word_frequency_distribution_results <- TextAnalysisR::word_frequency_distribution(
dfm_object,
continuous_variable = "year",
selected_terms = c("calculator", "computer"),
height = 500,
width = 900)
print(word_frequency_distribution_results$plot)
print(word_frequency_distribution_results$table)
}