library(syuzhet)
library(tm)
library(jsonlite)
library(ggplot2)
library(knitr)
library(kableExtra)


# knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(comment = NA)

\begin{center} Facebook Analysis Report \end{center} \begin{center}

 table_one<- params$table

     sentimentscores <- sort(round(colSums(prop.table((table_one[,1:8])))*100,digits = 2),decreasing = TRUE)
     # print(sentimentscores)
     #Create a dataframe that contains the sentiment scores
     sentimentscores <- as.data.frame(sentimentscores)
     #Rename the column names of the sentiment scores
     colnames(sentimentscores) <- c("Emotional %")

     ##Rename the row names of the sentiment scores
     Emotions <- c("anger","anticipation","disgust","fear","joy","sadness",
                   "surprise","trust")

 # table<- xtable(table_one)
 # print(sort(round(colSums(prop.table((table_one[,1:8])))*100,digits = 2),decreasing = TRUE))
 # kable(sentimentscores)


kable(sentimentscores, "latex")

\end{center}

table_two <- params$table
sentiment<- params$sentiment
    if(is.na(sentiment$Percentages)){
      print("No bar plot created")
    }else{
     barplot_one<- barplot(
        sort(round(colSums(prop.table(table_two[, 1:8])),digits =2),decreasing = TRUE),
        cex.names = 0.7,
        las = 1,
        main = " Emotional Sentiment by Word: 8 Basic Human Emotions",
        col = "lightgreen",
        xlim = c(0,11),
        ylim = c(0,1)
      )
     text(barplot_one, 0,labels = sort(round(colSums(prop.table(table_two[, 1:8])),digits =2),decreasing = TRUE),cex=1,pos=3)
    }

\newpage

\begin{center}

 table_one<- params$table

     ##Create the sentiment scores table
     sentimentscores <- sort(round(colSums(prop.table((table_one[,9:10]))),digits = 2),decreasing = TRUE)
     # print(sentimentscores)
     ##Create a dataframe that contains the sentiment scores
     sentimentscores <- as.data.frame(sentimentscores)
     ##Rename the column names of the sentiment scores
     colnames(sentimentscores) <- c("Emotional %")

     ##Rename the row names of the sentiment scores
     Emotions <- c("Positive","Negative")

  # pander::pandoc.table(sentimentscores)
kable(sentimentscores, "latex")

\end{center}

table_three <- params$table
sentiment<- params$sentiment
    if(is.na(sentiment$Percentages)){
      print("No bar plot created")
    }else{
# xlim_max <- round(max(table_three))
     barplot_one<- barplot(
        sort(colSums(prop.table(table_three[, 9:10])),decreasing = TRUE),
        cex.names = 0.7,
        las = 1,
        main = " Emotional Sentiment by Word",
        col= "lightgreen"
        ,xlim = c(0,3)
        ,ylim = c(0,1)
        # ,legend.text = sort(round(colSums(prop.table(table_three[, 9:10])),digits = 2),decreasing = TRUE)

      )
# text(barplot_one, 0,labels = sort(colSums(prop.table(table_three[, 9:10])),decreasing = TRUE),cex=1,pos=3)
    }
    docs<- params$docs
    s_v <- get_sentences(docs)
    s_v_sentiment <- get_sentiment(s_v)
    plot(
      s_v_sentiment,
      type="l",
      main= paste0(name," Messenger Timeline"),
      xlab = "Messenger Timeline",
      ylab= "Emotional Valence"
    )


gonzalezben81/facebookanalysis documentation built on June 20, 2024, 8:42 a.m.