0

I have drawn a graph during LDA analysis, but I want to get the plot in descending order based on the beta value.

ap_topics <- tidy(ap_lda, matrix = "beta")
ap_lda <- LDA(dtm.new, k = 15, control = list(alpha=0.1,seed=1234))
ap_topics <- tidy(ap_lda, matrix = "beta")

ap_top_terms <- ap_topics %>%
  group_by(topic) %>%
  top_n(15, beta) %>%
  ungroup() %>%
  arrange(topic, -beta)

ap_top_terms %>%
  mutate(term = reorder(term, beta)) %>%
  ggplot(aes(term,beta, fill = factor(topic))) +
  geom_col(show.legend = FALSE) +
  facet_wrap(~ topic, scales = "free") +
  coord_flip()

I want to make it easier to see the beta value for each term in the graph. What should I do?

ap_top_term structure

    > ap_top_terms
# A tibble: 150 x 3
   topic term       beta
   <int> <chr>     <dbl>
 1     1 hdr     0.0211 
 2     1 better  0.0101 
 3     1 content 0.00979
 4     1 dontt   0.00930
 5     1 thing   0.00749
 6     1 oled    0.00720
 7     1 black   0.00625
 8     1 model   0.00611
 9     1 make    0.00566
10     1 update  0.00556
# ... with 140 more rows

here is my current plot

enter image description here

Community
  • 1
  • 1
judy
  • 17
  • 5
  • Without your data or graphs showing your current/desired output, it's a bit hard to say. Is it related to [this question?](https://stackoverflow.com/questions/50376229/graph-with-ordered-bars-and-using-facets) – Punintended May 16 '18 at 17:11
  • @Punintended thank you. But why is paste doing over there? When I draw a graph, the numbers that appear in the words come out. I've updated my question. – judy May 17 '18 at 07:13

1 Answers1

0

Maybe this blog helps? https://nitinahuja.github.io/2017/nps-exploratory-text-analysis/

top_terms %>% 
mutate(term = reorder(term, beta)) %>%
ggplot(aes(term, beta, fill=factor(topic))) +
geom_col(show.legend = FALSE) +
facet_wrap(~ topic, scales = "free" ) +
coord_flip() +
guides(fill=FALSE) +
labs(title = "Terms in topics - By Comment", x = "Term", y = 
"Probability")

Or this one https://www.tidytextmining.com/topicmodeling.html library(ggplot2)

top_terms %>%
mutate(term = reorder_within(term, beta, topic)) %>%
ggplot(aes(term, beta, fill = factor(topic))) +
geom_col(show.legend = FALSE) +
facet_wrap(~ topic, scales = "free") +
coord_flip() +
scale_x_reordered()
  • Welcome to Stack Overflow. Do you think your answer would be more complete if you included the (or some) data and the resulting plot? [answer] gives guidance on answering questions. – Peter May 22 '20 at 13:13