I have a data frame with the column word
and I want to show the top 10 words in the text in a bar chart with ggplot.
This is the code:
text_df %>% count(word, sort = TRUE) %>% top_n(10)
The result is as expected. Now I want to show that in graph:
text_df %>% count(word, sort = TRUE) %>% top_n(10) >%>
ggplot(aes(word, n)) + geom_col()
The sorting is now lost and the ten words appear in a (for me) randomly order. Why is the sorting lost? Do I use the commands wrongly?