Chapter 15 Australian Open Winners

The following bar plot shows the Australian Open winners

getTournamentWinners = function(tournamentname,roundname ="All")
{
  if(roundname == "All")
  {
    return(
    matches %>%
      filter(tourney_name == tournamentname) %>%
      mutate(agediff = winner_age - loser_age) %>%
      mutate(rankingdiff = loser_rank - winner_rank) %>%
      mutate(htdiff = winner_ht - loser_ht)
    )
    
  }else
  {
    return(
    matches %>%
      filter(tourney_name == tournamentname) %>%
      filter(round == roundname) %>%
      mutate(agediff = winner_age - loser_age) %>%
      mutate(rankingdiff = loser_rank - winner_rank) %>%
      mutate(htdiff = winner_ht - loser_ht)
    )
  }
  
}

getGrandSlamWinners = function(roundname)
{
  return(
    matches %>%
      filter(tourney_level == "G") %>%
      filter(round == roundname) %>%
      mutate(agediff = winner_age - loser_age) %>%
      mutate(rankingdiff = loser_rank - winner_rank)
  )
}

plotTournamentWinners = function(tournament,titleName)
{
  tournament %>%
    group_by(winner_name) %>%
    summarise(Count = n()) %>%
    arrange(desc(Count)) %>%
    ungroup() %>%
    mutate(winner_name = reorder(winner_name,Count)) %>%
    
    
    ggplot(aes(x = winner_name,y = Count)) +
    geom_bar(stat='identity',colour="white", fill = fillColor2) +
    geom_text(aes(x = winner_name, y = 1, label = paste0("(",Count,")",sep="")),
              hjust=0, vjust=.5, size = 4, colour = 'black',
              fontface = 'bold') +
    labs(x = 'Winner', 
         y = 'Count', 
         title = titleName) +
    coord_flip() + 
    theme_bw()
  
}

ausopen = getTournamentWinners("Australian Open","F")
plotTournamentWinners(ausopen,'Aus Open Winners Count')

15.1 Distribution of Age of Australian Open Winners

summary(ausopen$winner_age)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   20.74   23.35   25.55   26.15   27.90   35.31
ausopen %>%
  ggplot(aes(x = winner_age)) +
  geom_histogram(binwidth = 1,fill = fillColor) +
  labs(x= 'Winner Age',y = 'Count', title = paste("Distribution of", ' Winner Age ')) +
  theme_bw()

The plot shows the Australian Open winners are mostly between 23 and 28.