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.50714 140
2 9.00862 116
3 8.91304 115
4 9.15385 104
5 9.23148 108
show.episodes[c(1:3, 6, 7, 17)] %>% head(10) %>% kable
season episode title rating votes year
1 1 Pilot 8.67019 2553 2008
1 2 Cat’s in the Bag… 8.47004 1936 2008
1 3 …And the Bag’s in the River 8.35666 1772 2008
1 4 Cancer Man 8.33314 1717 2008
1 5 Gray Matter 8.28146 1677 2008
1 6 Crazy Handful of Nothin’ 8.90366 1775 2008
1 7 A No-Rough-Stuff-Type Deal 8.68593 1713 2008
2 1 Seven Thirty-Seven 8.48435 1629 2009
2 2 Grilled 8.71199 1618 2009
2 3 Bit by a Dead Bee 8.27531 1511 2009

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 %>% 
  arrange(desc(last_watched_at)) %>% 
  head(5) %>% 
  kable
title season episode plays last_watched_at last_watched.year
Game of Thrones 4 10 3 2015-02-23 23:32:05 2015
Game of Thrones 4 9 3 2015-02-23 21:55:55 2015
Game of Thrones 4 8 2 2015-02-23 20:08:22 2015
Game of Thrones 4 7 3 2015-02-23 18:23:26 2015
The Walking Dead 5 11 1 2015-02-23 16:44:16 2015
# …and the movies in my trakt.tv collection
mymovies <- trakt.user.collection(user = "jemus42", type = "movies")

mymovies %>%
  select(title, year, collected_at) %>%
  arrange(collected_at) %>%
  head(5) %>%
  kable
title year collected_at
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 = as.numeric(round(max(last_watched_at) - min(last_watched_at)))) %>%
  arrange(desc(days)) %>%
  head(10) %>%
  kable
title days
The Walking Dead 718
Bob’s Burgers 716
Suits 714
Cougar Town 713
MythBusters 712
Family Guy 711
The Simpsons 711
Arrow 705
Elementary 677
Futurama 671

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.