Data Source : Kaggle

Packages Used

We begin by loading the packages that will be required throughout the course of our analysis.

library (tidyverse) 
library (ggfortify)
library (qdapTools)
library (caret)
library (tidyr)
library (corrplot)
library (ggpubr)
library (ggplot2)
library (PerformanceAnalytics)
library (factoextra)
library (fpc)
library (gganimate)
library (gifski)
library (av)
library (magick)
library (DT)

Reading the Data

data <-  read.csv("forbes-highest-paid-athletes-1990-2019/Forbes Richest Atheletes (Forbes Richest Athletes 1990-2019).csv")


attach(data)
set.seed(123456)


Displaying the Top 10 Values of the Data

head(data, 10)


Filtering the Top 10 Athletes for every year

#Since data is large, we filter top 10 players based on their rank vs the Year

rank <- data %>%
        group_by(Year) %>%
        mutate(Earnings.Label = paste0(" ", round(earnings....million.)," Million")) %>% 
        filter(Current.Rank <= 10) %>%
        ungroup()

datatable(head(rank, 20), class = 'cell-border stripe')

< / hr>

Animation 1: Racing Bar Chart of Top 10 Athletes vs Year

graph <-
  ggplot(rank,
         aes(Current.Rank, group = Name, fill = Name, color = Name)) +
  geom_tile(
    aes( y = earnings....million., height = earnings....million., width = 0.7), alpha = 0.8, color = NA, size = 4 ) +
  geom_text(
    aes(y = 0, label = paste(Name, " ")), vjust = 0.2, hjust = 1, size = 6 ) +
  geom_text(aes(y = earnings....million., label = Earnings.Label, hjust = 0), color = "#000000") +
  coord_flip(clip = 'off', expand = F) +
  scale_x_reverse() +
  guides(color = F) +
  labs(
    title = "Forbes Highest Paid Athletes from 1990 to 2019",
    x = NULL,
    y = NULL,
    caption = "Data Source : Kaggle (https://www.kaggle.com/parulpandey/forbes-highest-paid-athletes-19902019)"
  ) +
  theme_minimal () +
  theme( plot.title = element_text( hjust = 0.5, size = 28, colour = "blue" ),
    plot.caption = element_text(size = 10, colour = "#000000"),
    # Remove grid lines and axes ticks
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.ticks.y = element_blank(),
    axis.text.y  = element_blank(),
    axis.text.x = element_blank(),
    axis.title.x = element_blank(),
    plot.margin = margin(1, 1, 1, 4, "cm")
  ) +
  # Turn off legend
  theme(legend.position = "none") + 
  #Set transition
  transition_states(Year, transition_length = 4, state_length = 1) +
  ease_aes('cubic-in-out')


animate(graph, fps = 20, duration = 20,  width = 800, height = 600)

anim_save("earnings_graph.gif", graph)

To Be Continued …