> library(tm)
Loading required package: NLP
> load("tdm.rdata")
> frq <- rowSums (as.matrix (tdm))
> wt <- data.frame (word = names(frq), freq = frq)
> tx <- subset (wt, freq >)
Error: unexpected ')' in "tx <- subset (wt, freq >)"
> tx <- subset (wt, freq > 4)
> tx
                       word freq
artifici           artifici    5
car                     car    5
goal                   goal    5
human                 human   11
intellig           intellig   10
mani                   mani    7
research           research    6
task                   task    6
becom                 becom    6
control             control    5
expert               expert    6
might                 might    6
superintellig superintellig    5
system               system    7
will                   will    5
> library(syuzhet)
Warning message:
package ‘syuzhet’ was built under R version 3.5.3 
> library(plotly)
Loading required package: ggplot2

Attaching package: ‘ggplot2’

The following object is masked from ‘package:NLP’:

    annotate


Attaching package: ‘plotly’

The following object is masked from ‘package:ggplot2’:

    last_plot

The following object is masked from ‘package:stats’:

    filter

The following object is masked from ‘package:graphics’:

    layout

Warning message:
package ‘plotly’ was built under R version 3.5.3 
> syuzhet <- get_sentiment(tx, method="syuzhet")
Error in get_sentiment(tx, method = "syuzhet") : 
  Data must be a character vector.

--------------------------------
> txt <- c("Islamabad suffered great losses when it joined Washington’s War on Terror", "and in the end the US still pinned the blame on Pakistan for its own setbacks in Afghanistan")
--------------
> syuzhet <- get_sentiment(txt, method="syuzhet")
> bing <- get_sentiment(txt, method="bing")
> afinn <- get_sentiment(txt, method="afinn")
> nrc <- get_sentiment(txt, method="nrc")
> sentiments <- data.frame(syuzhet, bing, afinn, nrc)
> plot_ly(sentiments, x=~timestamp, y=~syuzhet, type="scatter", mode="jitter", name="syuzhet") %>%
+   add_trace(y=~bing, mode="lines", name="bing") %>%
+   add_trace(y=~afinn, mode="lines", name="afinn") %>%
+   add_trace(y=~nrc, mode="lines", name="nrc") %>%
+   layout(title="Recent sentiments of HDB in Singapore",
+          yaxis=list(title="score"), xaxis=list(title="date"))
Error in z[idx] : object of type 'closure' is not subsettable
------------------------------------------------------------------------

> emotions <- get_nrc_sentiment(txt)
Warning message:
The `printer` argument is deprecated as of rlang 0.3.0.
This warning is displayed once per session. 
> emo_bar = colSums(emotions)
> emo_sum = data.frame(count=emo_bar, emotion=names(emo_bar))
> emo_sum$emotion = factor(emo_sum$emotion, levels=emo_sum$emotion[order(emo_sum$count, decreasing = TRUE)])
> plot_ly(emo_sum, x=~emotion, y=~count, type="bar", color=~emotion) %>%
  layout(xaxis=list(title=""), showlegend=FALSE,
         title="Distribution of emotion categories for HDB (1-10 June 2017)")
Warning messages:
1: In RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

2: In RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

