Skip to content

Instantly share code, notes, and snippets.

@peterparkerspicklepatch
Last active November 7, 2015 22:17
Show Gist options
  • Save peterparkerspicklepatch/7d1f9b4c01e969125578 to your computer and use it in GitHub Desktop.
Save peterparkerspicklepatch/7d1f9b4c01e969125578 to your computer and use it in GitHub Desktop.
michaelbay.r
#Grab all of the info and put it into a dataframe
mikebay_movies <- lapply(vrottenrate(mikebay_movies$Film), function(x) as.data.frame(t(x), stringsAsFactors = FALSE))
mikebay_movies_dt <- rbindlist(mikebay_movies,fill=TRUE)
#Create a function that will download movie info
rottenrate <- function(movie){
require(RJSONIO)
link <- paste("http://www.omdbapi.com/?t=", movie, "&y=&plot=short&r=json&tomatoes=true", sep = "")
jsonData <- fromJSON(link)
return(jsonData)
}
vrottenrate <- Vectorize(rottenrate, "movie", SIMPLIFY = F)
#Create graph
mikebay_usergraph <-
ggplot(mikebay_movies_dt, aes(y = tomatoUserMeter, x = Released, label = Title)) +
geom_point(colour = "#535353", aes(size=BoxOffice + (.35 * mean(BoxOffice)))) +
geom_point(aes(size = BoxOffice)) + (aes(color = tomatoImage)) +
geom_text(hjust = .45, vjust = -.75, family = "SegoeUI", size = 5, colour = "#535353") +
ylab("Rotten Tomatos User Score") +
xlab("") +
ggtitle("Fall of Bayhem: How Micheal Bay movies have declined") +
theme (plot.title = element_text(size = 15, family = 'SegoeUI-Bold', face = 'bold', colour="#535353")) +
theme (axis.text.x = element_text(size = 12.0, family = "SegoeUI" , colour="#535353")) +
theme (axis.text.y = element_text(size = 12.0, family = "SegoeUI", colour="#535353")) +
theme (axis.title.y = element_text(size= 12,colour="#535353",face="bold",vjust=1.5, family = "SegoeUI")) +
theme (axis.title = element_text(size = 12.5, family = "SegoeUI")) +
theme (axis.text.x = element_text(size=11,colour="#535353",face="bold", family = "SegoeUI")) +
theme (axis.text.y = element_text(size=11,colour="#535353",face="bold", family = "SegoeUI")) +
theme (panel.background = element_rect(fill = '#F0F0F0')) +
theme (plot.background=element_rect(fill = '#F0F0F0')) +
theme (panel.grid.major=element_line(colour ="#D0D0D0",size=.75)) +
theme (axis.ticks = element_blank()) +
theme (legend.background = element_rect(fill='#F0F0F0')) +
scale_colour_manual(values = c('#336333', '#B03530'), name = "Fresh or Rotten") +
geom_hline(yintercept = 0,size = 1.2, colour = "#535353") +
scale_x_date(limits = c(as.Date("1994-1-1"),as.Date("2017-1-1"))) +
scale_size_continuous(labels=dollar, name="Box Office (Millions)")
#Pull movie list and clean it up
mikebay_movies <- html("http://en.wikipedia.org/wiki/Michael_Bay") %>%
html_nodes('#mw-content-text > table:nth-child(44)') %>%
html_table(fill = T) %>%
as.data.frame %>%
slice(-c(1,13)) %>%
transmute(Film
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment