Plotting text analysis with facet wrap

  • Plotting text analysis with facet wrap

     David updated 2 weeks, 5 days ago 2 Members · 6 Posts
  • jordan.trachtenberg

    Member
    November 11, 2020 at 8:41 am

    Would anyone have advice on how to create the plot in the “Negative Words” section of this blog post? I’m guessing it uses facet_wrap, but I’m not sure how you would be able to create a condition where it would look for the word2 words that follow a specified list of word1.

    https://jwinternheimer.github.io/blog/churn-survey-text-analysis/

  • David

    Organizer
    November 11, 2020 at 10:03 am

    I think this post by Julia Silge should do what you need to do. Specifically, check out the reorder_within() function from the tidytext package. Let me know if that works for you!

    • jordan.trachtenberg

      Member
      November 11, 2020 at 11:29 am

      Thanks @dgkeyes . The tutorial you shared did the trick for me. I’m actually using Julia Silge’s sentiment analysis tutorial and trying to do different visualizations using the Animal Crossing dataset. This is what I was able to get to work so far, where I first unnested data into bi-grams and removed stopwords from the dataset.

      As a test, I was looking through the top words that followed a certain list of “word1” in the bad reviews.

      # bigram_counts is a table of word1, word2, and n

      negative_words_plot <- bigram_counts %>%

      filter(rating == "Bad review (0-6)",

      word1 == c("shared", "island", "play", "multiple", "review", "single")) %>%

      group_by(word1) %>%

      filter(n > 1) %>%

      ungroup %>%

      mutate(word1 = as.factor(word1),

      word2 = reorder_within(word2, n, word1)) %>%

      ggplot(aes(n,

      word2,

      group = word1,

      fill = word1)) +

      geom_col(show.legend = FALSE) +

      labs(y = NULL,

      title = "Most common words",

      subtitle = "that follow...") +

      facet_wrap(~word1, scales = "free_y") +

      scale_y_reordered()


      negative_words_plot

  • David

    Organizer
    November 11, 2020 at 3:17 pm

    That’s awesome! Thanks for sharing. Not sure if you saw this (maybe it’s where you got the idea?), but Animal Crossing data was used recently for Tidy Tuesday. Here’s a video of David Robinson working with that data, for example.

    • jordan.trachtenberg

      Member
      November 12, 2020 at 6:24 am

      I did not know that he also did a video, but I’m really discovering the benefits of the Tidy Tuesday data sets for practice. My goal is to get comfortable with sentiment analysis and topic modeling so that I can apply those concepts to my own survey data. I’m watching his video now!

  • David

    Organizer
    November 12, 2020 at 6:50 am

    Awesome!

Log in to reply.

Original Post
0 of 0 posts June 2018
Now
The R for the Rest of Us community is live! Join regular office hours, ask questions in the forum, and more!