with(DATA, polarity(state, list(sex, adult)))
(poldat <- with(sentSplit(DATA, 4), polarity(state, person)))
counts(poldat)
scores(poldat)
plot(poldat)
poldat2 <- with(mraja1spl, polarity(dialogue,
list(sex, fam.aff, died)))
colsplit2df(scores(poldat2))
plot(poldat2)
plot(scores(poldat2))
poldat3 <- with(rajSPLIT, polarity(dialogue, person))
poldat3[["group"]][, "OL"] <- outlier_labeler(scores(poldat3)[,
"ave.polarity"])
poldat3[["all"]][, "OL"] <- outlier_labeler(counts(poldat3)[,
"polarity"])
htruncdf(scores(poldat3), 10)
htruncdf(counts(poldat3), 15, 8)
plot(poldat3)
plot(poldat3, nrow=4)
qheat(scores(poldat3)[, -7], high="red", order.b="ave.polarity")
## Create researcher defined polarity.frame
POLENV <- polarity_frame(positive.words, negative.words)
POLENV
ls(POLENV)[1:20]
## ANIMATION
#===========
(deb2 <- with(subset(pres_debates2012, time=="time 2"),
polarity(dialogue, person)))
bg_black <- Animate(deb2, neutral="white", current.speaker.color="grey70")
print(bg_black, pause=.75)
bgb <- vertex_apply(bg_black, label.color="grey80", size=20, color="grey40")
bgb <- edge_apply(bgb, label.color="yellow")
print(bgb, bg="black", pause=.75)
## Save it
library(animation)
library(igraph)
library(plotrix)
loc <- folder(animation_polarity)
## Set up the plotting function
oopt <- animation::ani.options(interval = 0.1)
FUN <- function() {
Title <- "Animated Polarity: 2012 Presidential Debate 2"
Legend <- c(-1.1, -1.25, -.2, -1.2)
Legend.cex <- 1
lapply(seq_along(bgb), function(i) {
par(mar=c(2, 0, 1, 0), bg="black")
set.seed(10)
plot.igraph(bgb[[i]], edge.curved=TRUE)
mtext(Title, side=3, col="white")
color.legend(Legend[1], Legend[2], Legend[3], Legend[4],
c("Negative", "Neutral", "Positive"), attributes(bgb)[["legend"]],
cex = Legend.cex, col="white")
animation::ani.pause()
})
}
FUN()
## Detect OS
type <- if(.Platform$OS.type == "windows") shell else system
saveHTML(FUN(), autoplay = FALSE, loop = TRUE, verbose = FALSE,
ani.height = 500, ani.width=500,
outdir = file.path(loc, "new"), single.opts =
"'controls': ['first', 'play', 'loop', 'speed'], 'delayMin': 0")
## Detect OS
type <- if(.Platform$OS.type == "windows") shell else system
saveHTML(FUN2(), autoplay = FALSE, loop = TRUE, verbose = FALSE,
ani.height = 1000, ani.width=650,
outdir = loc2, single.opts =
"'controls': ['first', 'play', 'loop', 'speed'], 'delayMin': 0")
FUN2(TRUE)
#=====================#
## Complex Animation ##
#=====================#
library(animation)
library(grid)
library(gridBase)
library(qdap)
library(reports)
library(igraph)
library(plotrix)
deb2dat <- subset(pres_debates2012, time=="time 2")
deb2dat[, "person"] <- factor(deb2dat[, "person"])
(deb2 <- with(deb2dat, polarity(dialogue, person)))
## Set up the network version
bg_black <- Animate(deb2, neutral="white", current.speaker.color="grey70")
bgb <- vertex_apply(bg_black, label.color="grey80", size=30, label.size=22,
color="grey40")
bgb <- edge_apply(bgb, label.color="yellow")
## Set up the bar version
deb2_bar <- Animate(deb2, as.network=FALSE)
## Generate a folder
loc2 <- folder(animation_polarity2)
## Set up the plotting function
oopt <- animation::ani.options(interval = 0.1)
FUN2 <- function(follow=FALSE, theseq = seq_along(bgb)) {
Title <- "Animated Polarity: 2012 Presidential Debate 2"
Legend <- c(.2, -1.075, 1.5, -1.005)
Legend.cex <- 1
lapply(theseq, function(i) {
if (follow) {
png(file=sprintf("%s/images/Rplot%s.png", loc2, i),
width=650, height=725)
}
## Set up the layout
layout(matrix(c(rep(1, 9), rep(2, 4)), 13, 1, byrow = TRUE))
## Plot 1
par(mar=c(2, 0, 2, 0), bg="black")
#par(mar=c(2, 0, 2, 0))
set.seed(20)
plot.igraph(bgb[[i]], edge.curved=TRUE)
mtext(Title, side=3, col="white")
color.legend(Legend[1], Legend[2], Legend[3], Legend[4],
c("Negative", "Neutral", "Positive"), attributes(bgb)[["legend"]],
cex = Legend.cex, col="white")
## Plot2
plot.new()
vps <- baseViewports()
uns <- unit(c(-1.3,.5,-.75,.25), "cm")
p <- deb2_bar[[i]] +
theme(plot.margin = uns,
text=element_text(color="white"),
plot.background = element_rect(fill = "black",
color="black"))
print(p,vp = vpStack(vps$figure,vps$plot))
animation::ani.pause()
if (follow) {
dev.off()
}
})
}
FUN2()
## Detect OS
type <- if(.Platform$OS.type == "windows") shell else system
saveHTML(FUN2(), autoplay = FALSE, loop = TRUE, verbose = FALSE,
ani.height = 1000, ani.width=650,
outdir = loc2, single.opts =
"'controls': ['first', 'play', 'loop', 'speed'], 'delayMin': 0")
FUN2(TRUE)
Run the code above in your browser using DataLab