0

I suspect this to be a fairly straightforward question for coders more experienced than myself.

I'm doing sentiment analysis, comparing review-sentiments of two companies, and I am using the "introduction to tidytext" by Silge et al (2021) and the Jane Austin example as offset.

Instead of performing the analysis across the books I'm using the two companies, named Hawes and Curtis and Indochino.

The aim is to produce a plot similar to this using my own data. Desired output-style

This is the plot as it looks now: Current output

This is the code from the paper:

bing <- get_sentiments("bing")
janeaustensentiment <- tidy_books %>%
  inner_join(bing) %>%
  count(book, index = line %/% 80, sentiment) %>%
  spread(sentiment, n, fill = 0) %>%
  mutate(sentiment = positive - negative)

library(ggplot2)
ggplot(janeaustensentiment, aes(index, sentiment, fill = book)) +
  geom_bar(stat = "identity", show.legend = FALSE) +
  facet_wrap(~book, ncol = 2, scales = "free_x")

This is my code:

bing <- get_sentiments("bing")
all_sentiment <- tokens_all %>% 
  inner_join( bing) %>% 
  count(company, index=line %/% 60, sentiment) %>% 
  spread(sentiment, n, fill = 0) %>% 
  mutate(sentiment = positive - negative)

ggplot(all_sentiment, aes(index, sentiment, fill= company)) +
  geom_bar(stat = "identity", show.legend = FALSE)
  facet_wrap(~company, ncol = 2, scales = "free_x")

This is shots of what the data looks like Data

Please let me know if you need the examples to be reproducible.

Thank you

Anders

Anders Jørgensen
  • 195
  • 1
  • 1
  • 9
  • Please note that it is always important to share minimal reproducible data, your code (what you have tried and where your are stuck) etc. in order for people to help you properly :) – bird May 26 '21 at 09:14
  • 3
    There is a missing `+` between `geom_bar` and `facet_wrap`. Probably the reason you don't get a facetted plot. – stefan May 26 '21 at 09:48
  • When you have looked at the code for too long and don't see the small errors. Thank you for the assistance. – Anders Jørgensen May 26 '21 at 10:02

0 Answers0