# This R environment comes with all of CRAN preinstalled, as well as many other helpful packages
# The environment is defined by the kaggle/rstats docker image: https://github.com/kaggle/docker-rstats
# For example, here's several helpful packages to load in 

library(ggplot2) # Data visualization
library(readr) # CSV file I/O, e.g. the read_csv function
library(needs)

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

system("ls ../input")

# Any results you write to the current directory are saved as output.
needs(dplyr, tidyr, stringr, lubridate, readr, ggplot2,
      MASS,
      pander, formattable, viridis)
      
list.files("../input") %>%
    as.list %>%
    pander
    
# train <- read_csv("../input/train.csv.zip")
train <- read_csv("../input/train.csv")
glimpse(train)

#
# DATA
#
train %>%
    sample_frac(.01) %>%
    ggplot(aes(x = accuracy)) +
    geom_density()
    
train %>%
    sample_frac(0.01) %>%
    ggplot(aes(x, y, z = accuracy)) +
    stat_summary_2d(fun = mean, bins = 50) +
    scale_fill_viridis()
    
train %>%
    filter(accuracy > 200) %>%
    # Since we're dealing with the subset that's over 200,
    # let's take a bigger sample.
    sample_frac(0.05) %>%
    ggplot(aes(x, y)) +
    geom_bin2d(bins = 50) +
    scale_fill_viridis() +
    lims(x = c(0, 10), y = c(0, 10))

#
# TIME
#    
train %>%
    sample_frac(.01) %>%
    ggplot(aes(x = time)) +
    geom_density()
    
train %>%
    sample_frac(.01) %>%
    ggplot(aes(x = x, y = time)) + 
    geom_bin2d(bins = 50)
    

    

    


