First step: Loading packages and trakt.tv credentials

suppressPackageStartupMessages(library(tRakt)) 
suppressPackageStartupMessages(library(dplyr)) # For convenience
library(ggplot2) # For plotting (duh)
library(knitr)   # for knitr::kable, used to render simple tables

# If you don't have a client.id defined in a key.json, use mine
if (is.null(getOption("trakt.client.id"))){
  get_trakt_credentials(client.id = "12fc1de7671c7f2fb4a8ac08ba7c9f45b447f4d5bad5e11e3490823d629afdf2")
}

Let’s pull some data

Getting more data

# Search a show and receive basic info
show          <- trakt.search("Breaking Bad")
# Save the slug of the show, that's needed for other functions as an ID
slug          <- show$ids$slug
slug
## [1] "breaking-bad"
# Get the season & episode data
show.seasons  <- trakt.getSeasons(slug) # How many seasons are there?
show.episodes <- trakt.getEpisodeData(slug, show.seasons$season, extended = "full")

# Glimpse at data (only some columns each)
rownames(show.seasons) <- NULL # This shouldn't be necessary
show.seasons[c(1, 3, 4)] %>% kable
season rating votes
1 8.44355 124
2 9.01961 102
3 8.93000 100
4 9.21739 92
5 9.23913 92
show.episodes[c(1:3, 6, 7, 17)] %>% head(10) %>% kable
season episode title rating votes firstaired.string
1 1 Pilot 8.67205 2540 2008-01-21
1 2 Cat’s in the Bag… 8.47242 1922 2008-01-28
1 3 …And the Bag’s in the River 8.36136 1760 2008-02-11
1 4 Cancer Man 8.33920 1704 2008-02-18
1 5 Gray Matter 8.29345 1663 2008-02-25
1 6 Crazy Handful of Nothin’ 8.90687 1761 2008-03-03
1 7 A No-Rough-Stuff-Type Deal 8.69036 1702 2008-03-10
2 1 Seven Thirty-Seven 8.48705 1622 2009-03-09
2 2 Grilled 8.71402 1612 2009-03-16
2 3 Bit by a Dead Bee 8.27689 1506 2009-03-23

Some example graphs

Plotting the data is pretty straight forward since I try to return regular data.frames without unnecessary ambiguitiy.

show.episodes$episode_abs <- 1:nrow(show.episodes) # I should probably do that for you.
show.episodes %>%
  ggplot(aes(x = episode_abs, y = rating, colour = season)) +
    geom_point(size = 3.5, colour = "black") +
    geom_point(size = 3) + 
    geom_smooth(method = lm, se = F) +
    labs(title = "Trakt.tv Ratings of Breaking Bad", 
         y = "Rating", x = "Episode (absolute)", colour = "Season")

show.episodes %>%
  ggplot(aes(x = episode_abs, y = votes, colour = season)) +
    geom_point(size = 3.5, colour = "black") +
    geom_point(size = 3) + 
    labs(title = "Trakt.tv User Votes of Breaking Bad Episodes", 
         y = "Votes", x = "Episode (absolute)", colour = "Season")

show.episodes %>%
  ggplot(aes(x = episode_abs, y = scale(rating), fill = season)) +
    geom_bar(stat = "identity", colour = "black", position = "dodge") +
    labs(title = "Trakt.tv User Ratings of Breaking Bad Episodes\n(Scaled using mean and standard deviation)", 
         y = "z-Rating", x = "Episode (absolute)", fill = "Season")

Now some user-specific data

User-specific functions (trakt.user.*) default to user = getOption("trakt.username"), which should have been set by get_trakt_credentials(), so you get your own data per default.
However, you can specifiy any publicly available user. Note that OAuth2 is not supported, so by “publicly available user”, I really mean only non-private users.

# Get a detailed list of shows/episodes I watched
myeps    <- trakt.user.watched(user = "jemus42", type = "shows.extended")

# Get a feel for the data
myeps[c(1:4, 6:7)] %>% 
  arrange(desc(lastwatched.posix)) %>% 
  head(5) %>% 
  kable
title season episode plays lastwatched.posix lastwatched.year
Game of Thrones 2 5 2 2015-02-16 07:06:50 2015
Game of Thrones 2 4 2 2015-02-16 05:53:45 2015
Game of Thrones 2 3 2 2015-02-16 04:22:19 2015
Game of Thrones 2 2 2 2015-02-16 02:52:07 2015
Game of Thrones 2 1 2 2015-02-16 00:55:29 2015
# …and the movies in my trakt.tv collection
mymovies <- trakt.user.collection(user = "jemus42", type = "movies")

mymovies %>%
  select(title, year, collected.posix) %>%
  arrange(collected.posix) %>%
  head(5) %>%
  kable
title year collected.posix
Howl’s Moving Castle 2004 2013-09-24 00:11:02
Stargate: Continuum 2008 2013-09-29 07:23:57
Stargate: The Ark of Truth 2008 2013-09-29 07:24:01
Stargate 1994 2013-09-29 07:24:03
Fight Club 1999 2013-09-29 07:38:59

I tried my best to make the returned data as flat and usable as possible.
I tried.

So, well, let’s see: Take watched shows, diff the oldest and youngest lastwatched values to get something like a “watch duration” going and aggregate using it:

myeps %>% 
  group_by(title) %>% 
  summarize(days = round(max(lastwatched.posix) - min(lastwatched.posix))) %>%
  arrange(desc(days)) %>%
  head(10) %>%
  kable
title days
Game of Thrones 711 days
Cougar Town 708 days
Suits 707 days
Arrow 705 days
Bob’s Burgers 704 days
Family Guy 704 days
The Simpsons 704 days
The Walking Dead 704 days
MythBusters 703 days
Elementary 677 days

It’s data like this that makes me wish I had been using trakt.tv forever. The potential for interesting data is great, but the limit is, as usual, the source of the data.