Skip to contents

Topics will be renamed in order of the input of new_names, which should be a character vector. For example, if you had topic_1 and topic_2, and you wanted to rename them 'sustainability' and 'climate_change', new_names should be input as new_names = c("sustainability", "climate_change"). This will mean that when plotting, the order is preserved. If you want to re-order the topics after renaming them, you should use `forcats::fct_reorder()` separately, or `mutate` & `factor()`

Usage

topics_rename(classified_df, k, new_names, topic_var = topic)

Arguments

classified_df

output of the `topics_classify` function

k

Value of k used to generate topic model

new_names

Desired new names in order of k

topic_var

The topic variable in your classified df

Value

Data Frame with topic variable renamed and ordered as a factor.

Examples

list_data <- SegmentR:::test_data()
#> removing stopwords
#> Making DTMs
#> making tuning grid
#> setting up LDAs
probabilities <- list_data$explore$probabilities[[1]]
data <- list_data$lda$data[[1]]

linked <- topics_link(data, probabilities)
classified <- topics_classify(linked, 0.75)
topics_rename(classified, k = 3, new_names = c("Name 1", "Name 2", "Name 3"))
#> # A tibble: 7 × 6
#>   rowid message                       url_var message_id topic topic_probability
#>   <dbl> <chr>                         <chr>   <chr>      <fct>             <dbl>
#> 1    20 #DiaDeLosMuertos #DayOfTheDe… https:… 20         Name…             0.843
#> 2    21 #DiaDeLosMuertos #DayOfTheDe… https:… 21         Name…             0.784
#> 3    69 Fun ones #HispanicHeritageMo… https:… 69         Name…             0.905
#> 4    80 Wake Up Texas! #VETOBETO. Be… https:… 80         Name…             0.792
#> 5    87 #halloween #cna #cnasofinsta… https:… 87         Name…             0.771
#> 6     3 Pura Belpré Award Winners 19… https:… 3          Name…             0.917
#> 7    49 Celebrating Hispanic Heritag… https:… 49         Name…             0.778