---
title: "Pixar Film Ratings"
description: |
  Explore the variation in box office ratings of the films.
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Pixar Film Ratings}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

## Overview

This vignette is to recreate an analysis on Pixar ratings that can be found
[here](https://pierrecom.github.io/Pixars%20Movies.html).


```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```


## Setup

```{r setup, warning=FALSE}
library(pixarfilms)
library(dplyr)
library(tidyr)
library(forcats)
library(ggplot2)
library(irr)
```


## Data wrangling

Before we can visualize our data, let's wrangle our data to help us visualize it
later on.

```{r}
df <-
  public_response %>%
  select(-cinema_score) %>%
  mutate(film = fct_inorder(film)) %>%
  pivot_longer(cols = c("rotten_tomatoes", "metacritic", "critics_choice"),
               names_to = "ratings",
               values_to = "value") %>%
  mutate(ratings = case_when(
    ratings == "metacritic" ~ "Metacritic",
    ratings == "rotten_tomatoes" ~ "Rotten Tomatoes",
    ratings == "critics_choice" ~ "Critics Choice"
  )) %>%
  drop_na()
```


## Ratings over time

Their first plot was comparing the Pixar films' ratings over time.

```{r fig.height=5, fig.width=6}
df %>%
  ggplot(aes(x = film, y = value, col = ratings)) +
  geom_point() +
  geom_line(aes(group = ratings)) +
  scale_color_brewer(palette = "Dark2") +
  labs(x = "Pixar film", y = "Rating value") +
  guides(col = guide_legend(title = "Ratings")) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5),
        legend.position = "bottom") 
```


**Verdict**: people and critics generally agree that Cars 2 was not as good as
the other Pixar films.


## Ratings by rating group

Next, let's group the rating categories to see if there is a consistency across.

```{r fig.height=6, fig.width=5}
df %>%
  ggplot(aes(x = ratings, y = value, col = ratings)) +
  geom_boxplot(width = 1.75 / length(unique(df$ratings))) +
  ggbeeswarm::geom_beeswarm() +
  ggrepel::geom_text_repel(data = . %>%
                             filter(film == "Cars 2" ) %>%
                             filter(ratings == "Rotten Tomatoes"),
                           aes(label = film),
                           point.padding = 0.4) +
  scale_color_brewer(palette = "Dark2") +
  guides(col = guide_legend(title = "Ratings")) +
  labs(x = "Rating group", y = "Rating value") +
  ylim(c(30, 100)) +
  theme_minimal() +
  theme(legend.position = "bottom") 
```


**Verdict**: people at Rotten Tomatoes generally like Pixar films more than
Metacritic and Critics Choice. The exception to this is Cars 2, which rated the
lowest out of all critic groups.


## Rating consistency

Are the groups statistically consistent? Let's perform
[an interclass correlation](https://en.wikipedia.org/wiki/Intraclass_correlation)
among the different critic groups.

```{r}
public_response %>%
  select(-c(cinema_score, film)) %>%
  drop_na() %>%
  icc(model = "twoway", type = "consistency")
```

**Verdict**: with a null hypothesis that all critic groups are not consistent,
for the 21 Pixar films we have data for all critic groups, all groups are
consistent in rating Pixar films (p < 0.001).


## Session information

```{r}
sessionInfo()
```

