#libraries & workspace
library("readr")
library("ggplot2")
setwd("~/Documents/Classes/Year 5/Fall 2019/Visual Analytics/Module 10")

#load data
hotdogs <- read_csv("http://datasets.flowingdata.com/hot-dog-contest-winners.csv")
## Parsed with column specification:
## cols(
##   Year = col_double(),
##   Winner = col_character(),
##   `Dogs eaten` = col_double(),
##   Country = col_character(),
##   `New record` = col_double()
## )
head(hotdogs)
## # A tibble: 6 x 5
##    Year Winner                       `Dogs eaten` Country      `New record`
##   <dbl> <chr>                               <dbl> <chr>               <dbl>
## 1  1980 Paul Siederman & Joe Baldini          9.1 United Stat…            0
## 2  1981 Thomas DeBerry                       11   United Stat…            0
## 3  1982 Steven Abrams                        11   United Stat…            0
## 4  1983 Luis Llamas                          19.5 Mexico                  0
## 5  1984 Birgit Felden                         9.5 Germany                 0
## 6  1985 Oscar Rodriguez                      11.8 United Stat…            0
#create a plot using ggplot 2
#=============================
#plot of hot dogs eaten by year
plot <- ggplot(hotdogs) + 
  geom_bar(aes(x = Year, y = `Dogs eaten`), stat="identity")
plot

#add lables and title to visualization
plot <- plot +
  labs(title = "Nathan's Hot Dog Eating Contest Results", subtitle = "1980-2010", fill = "Winner Nationality") +
  xlab("Year") +
  ylab("Hotdogs & Buns Eaten")
plot

#color bars by nationatily of winner
plot <- plot +
  geom_bar(aes(x = Year, y = `Dogs eaten`, fill = factor(Country)), stat="identity")
plot

#custom set colors (according to nation flag)
colors <- c("#FFCC00", "#EF3340", "#006847", "#2494d5")
plot <- plot +
  scale_fill_manual(values = colors)
plot