0

So I performed a sentiment analysis using tidy principles. I would like to plot the results in a comparison cloud (positive VS negative sentiments).

This is my code:

library(reshape2)
library(tidytext)

dtm_tidy %>%
filter()
dtm_tidy %>%
inner_join(get_sentiments("bing"),by=c(term="word")) %>%
count(term, sentiment, sort=TRUE) %>%
acast(term ~ sentiment, value.var = "n", fill = 0) %>%
comparison.cloud(colors = c("darkred", "darkgreen"), max.words=300, scale = c(0.3, 0.3), random.order=FALSE, rot.per=0.25, title.size = 1)

However, something seems to go wrong, because the titles (positive & negative) are not shown or rendered. I already changed scales and title.size but nothing could solve this issue.

Anybody an idea?

phiver
  • 23,048
  • 14
  • 44
  • 56
Lucinho91
  • 175
  • 2
  • 4
  • 16
  • I'm not sure what you're trying to do, and it's difficult to help without any sample data and a [reproducible minimal example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). The lines `dtm_tidy %>% filter()` seem superfluous, as you're not filtering anything. – Maurits Evers Mar 19 '18 at 11:54
  • Oh of course, I forgot to delete the lines `dtm_tidy %>% filter()`sorry! – Lucinho91 Mar 19 '18 at 13:07
  • Is there a way to move the titles up and down the Y-axis? – Lucinho91 Mar 19 '18 at 13:08
  • Please provide sample data and an [MVCE](https://stackoverflow.com/help/mcve)! – Maurits Evers Mar 19 '18 at 13:09

2 Answers2

2

I had a similar problem -- the titles were being cutoff on the top and the bottom of the rendered plot when I tried to save it as a pdf.

I was able to get the correct plot output by using "Portrait" orientation instead of "Landscape." I'm not sure why that fixed the issue but it did when saving it as a pdf or an image.

1

I found the answer to my problem: if this issue occurs to you, use the fixed.asp=TRUEcommand. Something like this:

comparison.cloud(colors = c("darkred", "darkgreen"), max.words=300, scale = c(0.3, 0.3), random.order=FALSE, rot.per=0.25,fixed.asp=TRUE,title.size = 1)

This should do the trick! :)

Lucinho91
  • 175
  • 2
  • 4
  • 16