Skip to content

Commit

Permalink
update simple_plot function
Browse files Browse the repository at this point in the history
  • Loading branch information
mjockers committed Dec 19, 2016
1 parent 92943b8 commit 2a78f9e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
34 changes: 22 additions & 12 deletions R/syuzhet.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,35 @@ rescale_x_2 <- function(v){
#' calculated for each sentence
#' @param title for image
#' @param legend_pos positon for legend
#' @param number of components for the filter
#' @export
simple_plot <- function(raw_values, title="Syuzhet Plot", legend_pos="top"){
wdw <- round(length(raw_values)*.1) # wdw = 10% of length
simple_plot <- function (raw_values, title = "Syuzhet Plot", legend_pos = "top", lps=10, window = 0.1){
wdw <- round(length(raw_values) * window)
rolled <- rescale(zoo::rollmean(raw_values, k = wdw, fill = 0))
half <- round(wdw/2)
rolled[1:half] <- NA
end <- length(rolled) - half
rolled[end:length(rolled)] <- NA
trans <- get_dct_transform(raw_values, x_reverse_len = length(raw_values), scale_range = T)
raw_lo <- stats::loess(raw_values ~ seq_along(raw_values), span=.5)
trans <- get_dct_transform(raw_values, low_pass_size = lps, x_reverse_len = length(raw_values),
scale_range = T)
x <- 1:length(raw_values)
y <- raw_values
raw_lo <- stats::loess(y ~ x, span = 0.5)
low_line <- rescale(stats::predict(raw_lo))
graphics::par(mfrow=c(2, 1))
graphics::plot(low_line, type = "l", ylim = c(-1,1), main = title, xlab = "Full Narrative Time", ylab = "Scaled Sentiment")
graphics::lines(rolled, col="blue")
graphics::lines(trans, col="red")
graphics::legend(legend_pos, c("Loess Smooth", "Rolling Mean", "Syuzhet DCT"), lty=1, lwd=1,col=c('black', 'blue', 'red'), bty='n', cex=.75)
normed_trans <- get_dct_transform(raw_values, scale_range = T)
graphics::plot(normed_trans,type = "l", ylim = c(-1,1), main = "Normalized Simple Shape", xlab = "Normalized Narrative Time", ylab = "Scaled Sentiment", col="red")
graphics::par(mfrow=c(1, 1))
graphics::par(mfrow = c(2, 1))
graphics::plot(low_line, type = "l", ylim = c(-1, 1), main = title,
xlab = "Full Narrative Time", ylab = "Scaled Sentiment", col="blue", lty = 2)
graphics::lines(rolled, col = "grey", lty = 2)
graphics::lines(trans, col = "red")
abline(h=0, lty=3)
graphics::legend(legend_pos, c("Loess Smooth", "Rolling Mean",
"Syuzhet DCT"), lty = 1, lwd = 1, col = c("blue", "grey",
"red"), bty = "n", cex = 0.75)
normed_trans <- get_dct_transform(raw_values, scale_range = T, low_pass_size = 5)
graphics::plot(normed_trans, type = "l", ylim = c(-1, 1),
main = "Simplified Macro Shape", xlab = "Normalized Narrative Time",
ylab = "Scaled Sentiment", col = "red")
graphics::par(mfrow = c(1, 1))
}

#' Discrete Cosine Transformation with Reverse Transform.
Expand Down
5 changes: 4 additions & 1 deletion man/simple_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a78f9e

Please sign in to comment.