How to plot multi-word expressions with quanteda

I am using the quanteda package in r for textual data analysis. I am interested in plotting some Keyword-in-context display using the kwic() command that is to useful to find multi-word expressions in tokens.

# Remove punctuation and symbols 
toks_comments <- tokens(comments_corpus, remove_punct = TRUE, remove_symbols = TRUE, padding = 
TRUE) %>% 
tokens_remove(stopwords("spanish"), padding = TRUE)


# Get relevant keywords and phrases from dictionary
servicio <- 
c("servicio","atencion","atención","personal","mesera","mesero","muchacha","muchacho","joven",
         "pelado", "pelada","meseros")

# Keyword-in-context
servicio_context <- kwic(toks_comments, pattern = phrase(servicio))  
View(servicio_context)

Once the previous lines have been run, I get the result that I have included in the photo. From that table in the photo, I am interested in graphing the "pre" and "post" column but I don't know how to do it. Is there a way to include the words in a multiword wordcloud or some other frequency visualization?

Here is the pic:"View(servicio_context)"

Upvotes: 1

Views: 123

Answers (1)

Harrison Jones
Harrison Jones

Reputation: 2506

You could do both a wordcloud and a frequency bar graph.

Wordcloud

library(quanteda.textplots)
library(quanteda)

dfm(servicio_context$pre) %>%
  textplot_wordcloud()

Bar Graph

library(ggplot2)

servicio_context %>%
  ggplot(aes(x = pre)) +
  geom_bar(stat = "count")

Upvotes: 0

Related Questions