Skip to content

Instantly share code, notes, and snippets.

@danhammer
Created May 16, 2019 14:12
Show Gist options
  • Save danhammer/e44731e0ec73aba9859f0f104fdec675 to your computer and use it in GitHub Desktop.
Save danhammer/e44731e0ec73aba9859f0f104fdec675 to your computer and use it in GitHub Desktop.
script graph
# Time series graph
library(jpeg)
x <- scan("star_wars_the_force_awakens.txt", what="", sep="\n")
lines <- strsplit(x, " => ")
script.series <- function(name, height) {
res <- rep(NA, 818)
i <- 1
for (l in lines) {
if (l[1] == name) {
res[i] <- sapply(strsplit(l[2], " "), length)/30
}
i <- i + 1
}
time <- 1:818
y <- rep(height, 818)
return(data.frame(idx=time, height=y, wc=res))
}
a <- script.series("REY", 400)
plot(a$idx, a$height, cex=a$wc, pch=19, col="#877b73", ylab="", xlab="", axes=F, ylim=c(190, 530))
img<-readJPEG("ray.jpg")
rasterImage(img,-30,360,20,440)
b <- script.series("FINN", 320)
points(b$idx, b$height, cex=b$wc, pch=19, col="#f7c65d")
img<-readJPEG("finn.jpg")
rasterImage(img,-30,280,20,360)
c <- script.series("LEIA", 480)
points(c$idx, c$height, cex=c$wc, pch=19, col="#f6e077")
img<-readJPEG("leia.jpg")
rasterImage(img,-30,440,20,520)
d <- script.series("HAN", 240)
points(d$idx, d$height, cex=d$wc, pch=19, col="#223559")
img<-readJPEG("han.jpg")
rasterImage(img,-30,200,20,280)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment