Import data

# excel file
data <- read_excel("../00_data/myData.xlsx")
data
## # A tibble: 27 × 5
##    number film            release_date        run_time film_rating
##     <dbl> <chr>           <dttm>              <chr>    <chr>      
##  1      1 Toy Story       1995-11-22 00:00:00 81       G          
##  2      2 A Bug's Life    1998-11-25 00:00:00 95       G          
##  3      3 Toy Story 2     1999-11-24 00:00:00 92       G          
##  4      4 Monsters, Inc.  2001-11-02 00:00:00 92       G          
##  5      5 Finding Nemo    2003-05-30 00:00:00 100      G          
##  6      6 The Incredibles 2004-11-05 00:00:00 115      PG         
##  7      7 Cars            2006-06-09 00:00:00 117      G          
##  8      8 Ratatouille     2007-06-29 00:00:00 111      G          
##  9      9 WALL-E          2008-06-27 00:00:00 98       G          
## 10     10 Up              2009-05-29 00:00:00 96       PG         
## # ℹ 17 more rows

Introduction

Questions

“Have Pixar movie runtimes changed over time, what are the typical runtime of a Pixar movie, whether movies with different ratings have different runtimes, and whether any movies have unusually short or long runtimes.”

Variation

Visualizing distributions

ggplot(data = data) +
    geom_bar(mapping = aes( x = film_rating))

data %>% count(film_rating)
## # A tibble: 4 × 2
##   film_rating     n
##   <chr>       <int>
## 1 G              13
## 2 N/A             3
## 3 Not Rated       1
## 4 PG             10
ggplot(data = data) +
    geom_histogram(mapping = aes (x = as.numeric(run_time)))

ggplot(data = data, mapping = aes( x = as.numeric(run_time), color = film_rating)) +
    geom_freqpoly()

Typical values

ggplot(data=data) +
    geom_histogram(mapping = aes( x = as.numeric(run_time)),
                   binwidth = 10)

Unusual values

data %>%
    ggplot(aes(x = as.numeric(run_time))) +
    geom_histogram()

data %>%
    ggplot(aes(x = as.numeric(run_time))) +
    geom_histogram(binwidth = 5) +
    coord_cartesian(xlim = c(75, 125))

Missing Values

data %>%
    ggplot(aes(x=number, y=run_time)) +
    geom_point()

data %>%
    mutate(run_time = ifelse(is.na(run_time), NA, run_time)) %>%
    ggplot(aes(x=number, y=run_time))+
    geom_point()

Covariation

data %>%
    ggplot(aes(x=film_rating, y=run_time)) +
    geom_boxplot()

A categorical and continuous variable

data %>%
    ggplot(aes(x=film_rating,y=run_time)) +
    geom_boxplot()

Two categorical variables

data %>%
    count(film ,film_rating) %>%
    ggplot(aes(x=film, y=film_rating, fill = n)) +
    geom_tile()

Two continuous variables

data %>%
    ggplot(aes(x=release_date,y =run_time)) +
    geom_point()

Patterns and models

data %>%
    ggplot(aes(x=release_date, y=run_time)) +
    geom_point() +
    geom_smooth()