Manawatu-Wanganui RegionOtago RegionCanterbury RegionSouthland RegionHawke's Bay RegionWaikato RegionWellington RegionGisborne RegionTaranaki RegionMarlborough RegionNorthland RegionBay of Plenty RegionTasman RegionAuckland RegionWest Coast RegionNelson Region01M2M3M4M5M
number_of_animals (Sum)number_of_human (Sum)AreaPopulation
# Set libPaths.
.libPaths("/Users/kannishida/.exploratory/R/3.3")

# Load required packages.
library(janitor)
library(lubridate)
library(hms)
library(tidyr)
library(urltools)
library(stringr)
library(readr)
library(broom)
library(RcppRoll)
library(tibble)
library(dplyr)
library(exploratory)

# Data Analysis Steps
exploratory::read_delim_file("/Users/kannishida/Downloads/Livestock_by_Regional.csv" , ",", quote = "\"", skip = 0 , col_names = TRUE , na = c("","NA") , locale=locale(encoding = "ASCII", decimal_mark = "."), trim_ws = FALSE , progress = FALSE) %>%
  exploratory::clean_data_frame() %>%
  filter(!str_detect(Area, "^Total")) %>%
  filter(str_detect(Livestock, "^Total")) %>%
  mutate(Year = mdy(Year), Area = str_c(Area, " Region"), Area = str_replace(Area, "Hawkes", "Hawke's")) %>%
  filter(year(Year) > 2000) %>%
  filter(year(Year) == 2013 & !is.na(Value)) %>%
  filter(Livestock == "Total sheep") %>%
  left_join(Population, by = c("Area" = "Area")) %>%
  filter(!is.na(Value.y)) %>%
  rename(number_of_animals = Value.x, number_of_human = Value.y) %>%
  mutate(sheep_human_ratio = number_of_animals / number_of_human, buckets = cut(sheep_human_ratio, breaks=c(-Inf, 1, 10, 20, 30, 40, Inf), 
labels=c("Less than Human", "1-10 Times More",
"10-20 Times More", "20-30 Times More", "30-40 Times More",
"Greater than 40 Times")))