R/sentiment.plot.R

Defines functions sentiment.plot

Documented in sentiment.plot

#' @title rSentiment Plots
#' @description Blank Description.
#' @param s Sentiment Data
#' @param n Name
#' Defaults to TRUE.
#' @keywords package
#' @return NULL
#' @export
#' @examples sentiment.plot()

sentiment.plot <- function(s, n) {

# Libraries

if('ggplot2' %in% rownames(installed.packages()) == TRUE) {
require(ggplot2)} else {
install.packages("ggplot2", repos = "http://cran.us.r-project.org")	
require(ggplot2)}

if('reshape' %in% rownames(installed.packages()) == TRUE) {
require(reshape)} else {
install.packages("reshape", repos = "http://cran.us.r-project.org")	
require(reshape)}

# Make New Data from Input

nk.sentiment <- s
nk.name <- n

nk.reshape <- reshape2::melt(nk.sentiment,
	variable.name = "emotion",
	value.name = "sentiment",
	id.vars = c("created_at", "favorite_count", "retweet_count","text"))
 
nk.sentiment.chart <- ggplot(nk.reshape, 
	aes(x = emotion, y = sentiment, fill = emotion)) + 
	theme_minimal() +
	coord_cartesian(ylim = c(0, 10)) +
	geom_jitter(color = "#ffffff", shape = 21, size = 2, alpha = .7, stroke = .15) +
	coord_flip() + labs(y = "", x = "", title = paste(nk.name, "NRC Sentiment")) +
	theme(legend.position = "none", text = element_text("Georgia", size = 18))
nk.sentiment.chart

# clear()

return(nk.sentiment.chart)

}
sabalicodev/sabali documentation built on Jan. 13, 2020, 2:22 p.m.