Student Details

Years since last AFL premiership as end of 2017 season

Last <- read.csv("F:/Data Visualisation/Assignment 3/Last premiership.csv")

Last$Teams <- factor(Last$Teams, levels = unique(Last$Teams)[order(Last$Years.since.last.premiership , decreasing = TRUE)])
p1 <- plot_ly(Last, x= ~Teams, y = ~Years.since.last.premiership, type = 'bar',
              hoverinfo = 'text',
              text = ~paste('</br> Team: ', Teams,
                            '</br> Years since last premiership: ', Years.since.last.premiership,
                            '</br> Last premiership year: ', Last.premiership.year),
            marker = list(line = list(color = 'rgb(0,0,0)', width = 1.5))) %>%
  layout(title = "Last AFL premiership as end of 2017 season",
         yaxis = list(zeroline = FALSE, title = "Number of years", range = c(0, 60)),
         xaxis = list(zeroline = FALSE, title = "Teams"), 
         width = 1000, height = 600,margin=m2)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
p1
## Warning: package 'bindrcpp' was built under R version 3.3.3







Premiership vs. non-premiership seasons from 1897 until 2017

Percent <- read.csv("F:/Data Visualisation/Assignment 3/Percentage of premiership seasons.csv")

Percent$Teams <- factor(Percent$Teams, levels = unique(Percent$Teams)[order(Percent$Percentage.non.premiership.season, decreasing = TRUE)])
updatemenus1 <- list(
  list(
    type = "buttons",
    direction = "down",
    xanchor = 'center',
    yanchor = "top",
    pad = list('r'= 0, 't'= 10, 'b' = 10),
    x = -0.5,
    type= 'buttons',
    buttons = list(
      list(
        label = "% of premiership seasons",
        method = "update",
        args = list(list(visible = c(TRUE, "legendonly")))),
      list(
        label = "% of non-premiership seasons",
        method = "update",
        args = list(list(visible = c("legendonly", TRUE)))),
      list(
        label = "Both",
        method = "update",
        args = list(list(visible = c(TRUE, TRUE))))
    )
  )
)

p2 <- plot_ly(Percent) %>%
  add_trace(y= ~Teams, x = ~Percentage.premiership.season, type = 'bar', legendgroup='group1', name = '% of premiership seasons', 
            text = ~Percentage.premiership.season, textposition = 'auto', orientation = 'h', visible = "legendonly",
            marker = list(line = list(color = 'rgb(0,0,0)', width = 1.5))) %>%
  
  add_trace(y= ~Teams, x= ~Percentage.non.premiership.season, type = 'bar', legendgroup='group2', name = '% of non premiership seasons', 
            text = ~Percentage.non.premiership.season, textposition = 'auto', orientation = 'h', visible = "legendonly", 
            marker = list(line = list(color = 'rgb(0,0,0)', width = 1.5))) %>%
  
  layout(barmode = 'stack', title = "Premiership vs. non-premiership seasons from 1897 until 2017",
         xaxis = list(zeroline = FALSE, title = "Percentage (%)", range = c(0, 100)),
         yaxis = list(zeroline = FALSE, title = "Teams", range = c(~Teams) ),
         updatemenus=updatemenus1,  
         width = 1000, height = 600, margin=m)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
p2







AFL and VFL premierships/runners-up from 1897 until 2017

AFL <- read.csv("F:/Data Visualisation/Assignment 3/AFL premiership and runnersup.csv")

AFL$Teams <- factor(AFL$Teams, levels = unique(AFL$Teams)[order(AFL$value, decreasing = TRUE)])
p3 <- plot_ly(AFL, y = ~Teams, x = ~value, color= ~variable, colors=c("#0077ae", "#ff7400")) %>%
      add_bars(orientation = 'h', 
             hoverinfo = 'text',
             text = ~paste('</br> Team: ', Teams,
                           '</br> Result: ', variable,
                           '</br> Count: ', value2,
                           '</br> Years: ', years,
                           '</br>       ', years2),
             marker = list(line = list(color = 'rgb(0,0,0)', width = 1.5))) %>%
  layout(bargap = 0.1, barmode = 'overlay',
         title = "AFL and VFL premierships/runners-up from 1897 until 2017",
         legend = list(x = 0.835, y = 1),
         xaxis = list(title = "Count", range= c(-30,30),
                      tickmode = 'array', tickvals = c(-30, -20, -10, 0, 10, 20, 30),
                      ticktext = c('30','20', '10', '0', '10', '20', '30')),
         yaxis = list(title = "Teams"),
         autosize = F, width = 1000, height = 600, margin=m)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
p3







References

The Conversation article:

Wickham, G 2017, ‘The glory or the ’gravel’: what keeps fans flocking to the AFL?’, The Conversation, accessed September 29, 2017, from https://theconversation.com/the-glory-or-the-gravel-what-keeps-fans-flocking-to-the-afl-47998

Original data sources:

‘AFL Tables - Grand Finals’ 2017, accessed September 29, 2017, from http://afltables.com/afl/teams/allteams/gfgames.html

‘List of Australian Football League premiers’ 2017, accessed September 29, 2017, from https://en.wikipedia.org/wiki/List_of_Australian_Football_League_premiers