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()
#> 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: 12 × 6
#>    rowid message                      url_var message_id topic topic_probability
#>    <dbl> <chr>                        <chr>   <chr>      <fct>             <dbl>
#>  1    16 Meeting Soon To Discuss His… https:… 16         Name…             0.833
#>  2    20 #DiaDeLosMuertos #DayOfTheD… https:… 20         Name…             0.784
#>  3    21 #DiaDeLosMuertos #DayOfTheD… https:… 21         Name…             0.784
#>  4    25 Making clay masks is so muc… https:… 25         Name…             0.867
#>  5    28 Celebrating #HispanicHerita… https:… 28         Name…             0.778
#>  6    38 Our 4th and 5th graders did… https:… 38         Name…             0.754
#>  7    40 Our proud principal practic… https:… 40         Name…             0.822
#>  8    44 This year, my boys and I ta… https:… 44         Name…             0.796
#>  9    69 Fun ones #HispanicHeritageM… https:… 69         Name…             0.762
#> 10    73 Happy Halloween from all of… https:… 73         Name…             0.784
#> 11    80 Wake Up Texas! #VETOBETO. B… https:… 80         Name…             0.762
#> 12    85 O'Farrill Learning Center H… https:… 85         Name…             0.848