Ordering Feeling Table(Tidytext)

Asked

Viewed 117 times

1

I am trying to create a table based on the Chapter-Book-Feeling-n leaving the Chapter always in original order:"The Boy Who Lived", "The Vanishing Glass," "The Letters from No One", "The Keeper of Keys," "Diagon Alley," "The Journey from Platform Nine and Three Quarters", "The Sorting Hat," "The Potions Master," "The Midnight Duel," "Halloween," "Quidditch," "The Mirror of Erised", "Nicholas Flamel", "Norbert the Norwegian Ridgeback", "The Forbidden Forest," "Through the Trapdoor," "The Man with Two Faces"

Only when doing this table the chapter is ordered in alphabetical order. I have tried to give Sort=FALSE in Count but nothing works....

I’m doing like this:

cap=c("The Boy Who Lived",
    "The Vanishing Glass",
    "The Letters from No One",
    "The Keeper of Keys",
    "Diagon Alley",
    "The Journey from Platform Nine and Three Quarters",
    "The Sorting Hat",
    "The Potions Master",
    "The Midnight Duel",
    "Halloween",
    "Quidditch",
    "The Mirror of Erised",
    "Nicholas Flamel",
    "Norbert the Norwegian Ridgeback",
    "The Forbidden Forest",
    "Through the Trapdoor",
    "The Man with Two Faces")

PedraFilosofal = tibble(Capitulo = cap,
                      Texto = philosophers_stone,
                      Livro = "PedraFilosofal")

LetraPF = PedraFilosofal %>% 
     group_by(Capitulo,Livro) %>% 
     unnest_tokens(Letra,Texto)

SemSWPF = LetraPF %>% 
     anti_join(stop_words,by=c("Letra"="word"))

TabelaSentimentosCap = SemSWPF %>% 
     inner_join(get_sentiments("bing"),by = c("Letra" = "word")) %>% 
     count(Livro,sentiment) %>% 
     spread(sentiment,n,fill=0) %>%  
     mutate(Sentimento = positive-negative)

I’m Using The Tidytext and Tidyverse Package,. A TABELA FICA DESSA FORMA:

  • Try using the "factor" to keep the light in the order you want.

1 answer

1

Add the code

PedraFilosofal$Capitulo <- factor(PedraFilosofal$Capitulo, levels = cap)

right after creating your tibble

Browser other questions tagged

You are not signed in. Login or sign up in order to post.