How can i restrict bars in poltly or ggplot2?

I want to make a graph for frequency of word. How can i restrict R to show just top 5 word within the plotly bar graph?

I solved it!

it's simply:

words <- sort(colSums(train.tokens.matrix),decreasing=TRUE)
df <- data.frame(word = names(words),freq=words)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.