Skip to content

Instantly share code, notes, and snippets.

@yrochat
Created January 21, 2016 23:25
Show Gist options
  • Save yrochat/6c1c3f9062806151c471 to your computer and use it in GitHub Desktop.
Save yrochat/6c1c3f9062806151c471 to your computer and use it in GitHub Desktop.
Extract from the Mobygames db the number of video games per year
url <- "http://www.mobygames.com/browse/games/"
years <- as.character(1971:2015)
# library(plyr)
# l_ply(years, function(x) dir.create(str_c("allgames/", x, "/")))
library(rvest)
library(stringr)
hey <- lapply(years, . %>%
str_c(url, ., "/list-games/")
%>% read_html()
%>% html_nodes(xpath = "//*[@id='main']/div/div[2]/div/text()[3]")
%>% html_text())
year_games <- unlist(hey)
year_games <- str_extract(year_games, "[0-9]+")
year_games <- as.numeric(year_games)
games <- data.frame(year = as.numeric(years), count = year_games)
library(ggplot2)
g <- ggplot(games, aes(x = year, y = count)) + geom_bar(stat = "identity")
g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment