1 Loading libraries

1.1 Description of the TYPE of graph (e.g. Bar chart, Sankey Dendogram, etc.)

I was always facinated with Bar charts, because in my opinion they provide easy way to represent data, show trends, discrete numerical comparisons, and they are easy to comprehend, while they can present lots of information.

1.2 Description of the DATA:

For this project I am going to use Nathan’s Hot Dog Eating Context.

The dataset containsfolowing variables: 1. year of the contest as a whole numeric variable 2. winner’s name as alphacharacter variable 3. gender as alphacharacter variable 4. number of hot dogs eaten as a real numeric variable 5. affiliation with a professional hot dog eating organization as a categorical variable (none, former, current)

2 The code below reads data from a CSV file into a dataframe, which will be used for future duilding of the graph.

hdm_affil <-read_csv(here::here("hot_dog_contest_with_affiliation.csv"),
  col_type=cols(
    affiliated = col_factor(levels=NULL),
    gender=col_factor(levels=NULL)
  )) %>%
  mutate(post_iforce = year>=1997) %>%
  filter(year >= 1981 & gender =="male")

2.1 Bars in the Bar chart can be vertical or horizontal:

Vertical lines are useful to present a trend over time. I am going to use ggplot to show two different forms of bar charts.

ggplot(hdm_affil, aes(x = year, y = num_eaten)) +
  geom_col()

Horizontal bars present a good comparison between several groups:

ggplot(hdm_affil, aes(x =num_eaten , y =year )) +
  geom_col()

2.2 Representation Description:

On the graph I am trying to show a few things:\n

  1. The trend in hot dog eating over time
ggplot(hdm_affil, aes(x = year, y = num_eaten)) +
  geom_col()

The above bar plot above shows how the consumption of hot dogs increased in the years. The height of each bar corresponds to the number of hot dogs eaten by a contestant and can be estimated by number on the y-axis. It is a good way to estimate quantitative data. The position of each bar corresponds to a year the competition took place. It is noticeable, that in 2001 there was a significant jump, as the consumption increased twice as much as in previous year. This is a very simple, primitive plot, which uses only default built-in options of ggplot.

Now we can try to figure out why it happened.

We have a theory: may be creation of professional organization of hot dog eaters had something to do with it?

2.3 How did creation and affiliation of professional hot dog eating organizationaffected the number of hot dogs consumed

To answer this question I am going to use ggplot again, but now I am going to use some customization: 1. I am going to label my axises with custom labels: “Year” for x-axis and “Hot Dogs and Buns Consumed” for y-axis 2. I am also going to fill the bars with distict colors, according to affiliation with IFOCE organization.

affil_plot <- ggplot(hdm_affil, aes( x=year, y=num_eaten))+
  geom_col(aes(fill=affiliated))+
  labs(x="Year", y="Hot Dogs and Buns Consumed")+
  ggtitle("Nathan's Hot Dog Eating Contest Results, 1981-2017")+
  scale_fill_manual(values=c('#E9602B','#2277A0','#CCB683'),
                              name="IFOCE-affiliation")

affil_plot <-affil_plot +
  scale_y_continuous(expand = c(0,0),
                      breaks = seq(0,70,10))+
  scale_x_continuous(expand = c(0,0))

affil_plot <- affil_plot + 
  coord_cartesian(xlim = c(1980, 2018), ylim = c(0,80))

affil_plot

The plot above now has colors. The colors shows if there was an affiliation of the hot dog eaters with the professional organization. It seems our idea was right: The former or present affiliation with IFOCE is related to a significant increased in consumprion of hot dogs. Our data also allows us to compare contestants by gender.

2.4 Is there a deifference in number of hot dogs eaten by gender

I’m going to add custom annotations, for ease of understaning the coloring schema

mikes_plot <- ggplot(hdm_affil, aes(x=year, y=num_eaten))+
  geom_col(aes(fill=affiliated))+
  labs(x="Year", y="Hot Dogs and Buns Consumed")+
  ggtitle("Nathan's Hot Dog Eating Contest Results, 1981-2017")+
  scale_fill_manual(values = c('#E9602B', '#2277A0', '#CCB683'),
                    name = "IFOCE-affiliation")



hdm_females <- read_csv(here::here("hot_dog_contest_with_affiliation.csv"),
  col_types = cols(
    affiliated = col_factor(levels= NULL),
    gender = col_factor(levels = NULL)
    )) %>%
  mutate(post_ifoce = year >=1997) %>%
  filter(year >= 1981 & gender == "female")
  
mikes_ann <- mikes_plot +
  guides(fill=FALSE) +
  coord_cartesian(xlim=c(1980, 2019), ylim=c(0,85))+
  annotate('segment', x=1980.75, xend=2000.25, y=30, yend=30, size=0.5, color="#CCB683")+
  annotate('segment', x=1980.75, xend=1980.75, y=30, yend=28, size=0.5, color="#CCB683")+
  annotate('segment', x=2000.25, xend=2000.25, y=30, yend=28, size=0.5, color="#CCB683")+
  annotate('segment', x=1990, xend=1990, y=33, yend=30, size=0.5, color="#CCB683")+
annotate('text', x=1990, y=36, label="No MLE/IFOCE Affiliation", color="#CCB683", family="Lato", hjust=0.5, size = 3) +
annotate('segment', x=2000.75, xend=2006.25, y= 58, yend=58, size=0.5, color="#2277A0") +
annotate('segment', x=2000.75, xend=2000.75, y= 58, yend=56, size=0.5, color="#2277A0") +
annotate('segment', x=2006.25, xend=2006.25, y= 58, yend=56, size=0.5, color="#2277A0") +
annotate('segment', x=2003.5, xend=2003.5, y= 61, yend=58, size=0.5, color="#2277A0") +
annotate('text', x=2003.5, y=65, label="MLE/IFOCE\nFormer Member", color="#2277A0", family="Lato", hjust=0.5, size = 3) +
annotate('segment', x=2006.75, xend=2017.25, y= 76, yend=76, size=0.5, color="#E9602B") +
annotate('segment', x=2006.75, xend=2006.75, y= 76, yend=74, size=0.5, color="#E9602B") +
annotate('segment', x=2017.25, xend=2017.25, y= 76, yend=74, size=0.5, color="#E9602B") +
annotate('segment', x=2012, xend=2012, y= 79, yend=76, size=0.5, color="#E9602B") +
annotate('text', x=2012, y=82, label="MLE/IFOCE Current Member", color="#E9602B", family="Lato", hjust=0.5, size = 3)

This little snipet pf code actually will add women contestants on the graph as a different shade of orange

mikes_w_females <- mikes_ann +
  geom_col(data = hdm_females,
            width = 0.75,
            fill = "#F68A39")

This code will add custom caption on the graph, which will explain when the female contestant’s data shows up in the data set.

caption <- paste(strwrap("* From 2011 on, separate Men's and Women's prizes have been awarded. All female champions to date have been MLE/IFOCE-affiliated.", 70), collapse="\n")

mikes_w_females +
  # now an asterisk to set off the female scores, and a caption
  annotate('text', x = 2018.5, y = 39, label="*", family = "Lato", size = 8) +
  labs(caption = caption) +
  theme(plot.caption = element_text(family = "Lato", size=8, hjust=0, margin=margin(t=15)))

2.5 How to read it & What to look for:

Now, this final graph represents all available data on one page. It shows the trend over time: we can see increase in consumption over time

2.6 Presentation of qualitative/categorical data-1:

The color schema represents categorical and qualitative data on the graph. Ii is also used to group and differentiate between different groups of items on the graph. For example on the current graph it helps to group members without MLE/IFOCE affiliation, fromer members and current members of MLE/IFOCE

2.7 Presentation of qualitative/categorical data-2:

Another important feature of this graph is that we use different shades of orange to show two categorical data sets: There were two separate categories of winners in the contest: men and women on the same year’s graph.

2.8 The annotations:

The annotations helps to understand the grouping on the graph. In additiona to coloring schema and clearly deliniates when MLE/IFOCE members started to participate in the competition and explains the colors present on the graph.

2.9 Captions:

We also have a caption on the graph, which explains the different shades of orange and how it is related to the number of hot dogs consumed by men vs. women

2.10 Variations and alternatives:

The two major variations of the bar plot we discussed in the beginning of the presentation: they are vertical and horizontal bars. In addition we can always change color schema… although it does not always work well:

mikes_plot <- ggplot(hdm_affil, aes(x=year, y=num_eaten))+
  geom_col(aes(fill=affiliated))+
  labs(x="Year", y="Hot Dogs and Buns Consumed")+
  ggtitle("Nathan's Hot Dog Eating Contest Results, 1981-2017")+
  scale_fill_manual(values = c('#4682B4', '#B22222', '#FFD700'),
                    name = "IFOCE-affiliation")



hdm_females <- read_csv(here::here("hot_dog_contest_with_affiliation.csv"),
  col_types = cols(
    affiliated = col_factor(levels= NULL),
    gender = col_factor(levels = NULL)
    )) %>%
  mutate(post_ifoce = year >=1997) %>%
  filter(year >= 1981 & gender == "female")
  
mikes_ann <- mikes_plot +
  guides(fill=FALSE) +
  coord_cartesian(xlim=c(1980, 2019), ylim=c(0,85))+
  annotate('segment', x=1980.75, xend=2000.25, y=30, yend=30, size=0.5, color="#FFD700")+
  annotate('segment', x=1980.75, xend=1980.75, y=30, yend=28, size=0.5, color="#FFD700")+
  annotate('segment', x=2000.25, xend=2000.25, y=30, yend=28, size=0.5, color="#FFD700")+
  annotate('segment', x=1990, xend=1990, y=33, yend=30, size=0.5, color="#FFD700")+
annotate('text', x=1990, y=36, label="No MLE/IFOCE Affiliation", color="#FFD700", family="Lato", hjust=0.5, size = 3) +
annotate('segment', x=2000.75, xend=2006.25, y= 58, yend=58, size=0.5, color="#B22222") +
annotate('segment', x=2000.75, xend=2000.75, y= 58, yend=56, size=0.5, color="#B22222") +
annotate('segment', x=2006.25, xend=2006.25, y= 58, yend=56, size=0.5, color="#B22222") +
annotate('segment', x=2003.5, xend=2003.5, y= 61, yend=58, size=0.5, color="#B22222") +
annotate('text', x=2003.5, y=65, label="MLE/IFOCE\nFormer Member", color="#B22222", family="Lato", hjust=0.5, size = 3) +
annotate('segment', x=2006.75, xend=2017.25, y= 76, yend=76, size=0.5, color="#4682B4") +
annotate('segment', x=2006.75, xend=2006.75, y= 76, yend=74, size=0.5, color="#4682B4") +
annotate('segment', x=2017.25, xend=2017.25, y= 76, yend=74, size=0.5, color="#4682B4") +
annotate('segment', x=2012, xend=2012, y= 79, yend=76, size=0.5, color="#4682B4") +
annotate('text', x=2012, y=82, label="MLE/IFOCE Current Member", color="#4682B4", family="Lato", hjust=0.5, size = 3)

mikes_w_females <- mikes_ann +
  geom_col(data = hdm_females,
            width = 0.75,
            fill = "#F68A39")
caption <- paste(strwrap("* From 2011 on, separate Men's and Women's prizes have been awarded. All female champions to date have been MLE/IFOCE-affiliated.", 70), collapse="\n")

mikes_w_females +
  # now an asterisk to set off the female scores, and a caption
  annotate('text', x = 2018.5, y = 39, label="*", family = "Lato", size = 8) +
  labs(caption = caption) +
  theme(plot.caption = element_text(family = "Lato", size=8, hjust=0, margin=margin(t=15)))

2.11 How to create it: Methods section was integrated into the main presentation.