In [5]:
#Load libraries
library(ggplot2)
library(dplyr)
In [15]:
spon_sentiment_df <- na.omit(read.csv("/home/hao/workspace/6thSemester/DataScience/data/SPON_All.csv", fileEncoding="UTF-16"))
head(spon_sentiment_df)
In [7]:
spon_sentiment_byYear <- spon_sentiment_df %>%
group_by(year) %>%
summarise(sum_positiv_abs = sum(positiv_abs), sum_neutral_abs = sum(neutral_abs), sum_negativ_abs = sum(negativ_abs), sum_positiv_rel = sum(positiv_rel), sum_neutral_rel = sum(neutral_rel), sum_negativ_rel = sum(negativ_rel))
head(spon_sentiment_byYear)
In [8]:
calc_polarity <- function(positiv, neutral, negativ) {
sum <- positiv + neutral + negativ
polarity <- (positiv - negativ) / sum;
polarity
}
sum_polarity <- mapply(calc_polarity, positiv = spon_sentiment_byYear$sum_positiv_abs, neutral = spon_sentiment_byYear$sum_neutral_abs, negativ = spon_sentiment_byYear$sum_negativ_abs)
In [9]:
spon_sentiment_byYear <- cbind(spon_sentiment_byYear, sum_polarity)
head(spon_sentiment_byYear)
In [10]:
ggplot(spon_sentiment_byYear, aes(x = year, y = sum_polarity)) + geom_line() + geom_point() + geom_smooth()
In [17]:
ggplot(spon_sentiment_byYear, aes(x = year)) +
geom_line(aes(y=sum_positiv_rel/365, color = "sum_positiv_rel")) +
geom_line(aes(y=sum_neutral_rel/365, color = "sum_neutral_rel")) +
geom_line(aes(y=sum_negativ_rel/365, color = "sum_negativ_rel"))
In [13]:
In [ ]: