Table of feeling ordering (Tidytext)

1

I'm trying to create a table that has the Chapter-Book-Feeling-n leaving the Chapter always in the 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"

So when doing this table the chapter is ordered by alphabetical order. I already tried to sort = FALSE no count but nothing works ....

I'm doing 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, not to mention the Harry Potter package I took from gitgub.

    
asked by anonymous 14.07.2018 / 20:18

1 answer

1

Add the code

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

soon after creating your tibble

    
22.11.2018 / 13:18