Creating Pizza Plots for Football Data

This document will give instructions on how to create Pizza Plots to analyse Football Data, in specific player data. These Pizza Plots are great for analysis because they immediately compare the variables that you are analyzing with the rest of the players or teams from the season that you are analyzing. It is a very useful tool for comparisons.

Firstly load the required libraries:

devtools::install_github("JaseZiv/worldfootballR")
## Skipping install of 'worldfootballR' from a github remote, the SHA1 (dc489beb) has not changed since last install.
##   Use `force = TRUE` to force installation
library(worldfootballR)
devtools::install_github("abhiamishra/ggshakeR")
## Skipping install of 'ggshakeR' from a github remote, the SHA1 (51b7c2df) has not changed since last install.
##   Use `force = TRUE` to force installation
library(ggshakeR)
library(tidyverse)
## Warning: package 'dplyr' was built under R version 4.3.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Acquire Desired Player URL

For this example we are going to be looking at the Albanian striker Armando Broja

## This function grabs Armando Broja's stats from the FbRef website and creates a data frame with it.

## To gather the statistics, go to the FbRef website, look up the desired player you want to look at and copy the url and paste it in the code below


Armando_Broja <- fb_player_scouting_report("https://fbref.com/en/players/97220da2/Armando-Broja",
                                       pos_versus = "primary")

Now you have a database that has all of Armando Broja statistics since the beginning of his career.

However, all the statistics aren’t very useful for analysis so let’s filter down to only look at 1 season, in specific 2021-2022 when he was playing at Southampton

Filter Database to select specific season

Firstly, let’s create an index in the database to help us in the future with our plot creation.

#Create an index for Armando_Broja
Armando_Broja$index <- 1:nrow(Armando_Broja)

Now let’s actually filter the database

Armando_Broja %>% filter(scouting_period == "2021-2022 Premier League")
##            Player   Versus              StatGroup
## 2   Armando Broja Forwards               Standard
## 3   Armando Broja Forwards               Standard
## 4   Armando Broja Forwards               Standard
## 5   Armando Broja Forwards               Standard
## 6   Armando Broja Forwards               Standard
## 7   Armando Broja Forwards               Standard
## 8   Armando Broja Forwards               Standard
## 9   Armando Broja Forwards               Standard
## 10  Armando Broja Forwards               Standard
## 11  Armando Broja Forwards               Standard
## 12  Armando Broja Forwards               Standard
## 13  Armando Broja Forwards               Standard
## 15  Armando Broja Forwards               Standard
## 16  Armando Broja Forwards               Standard
## 17  Armando Broja Forwards               Standard
## 20  Armando Broja Forwards               Shooting
## 21  Armando Broja Forwards               Shooting
## 22  Armando Broja Forwards               Shooting
## 23  Armando Broja Forwards               Shooting
## 24  Armando Broja Forwards               Shooting
## 25  Armando Broja Forwards               Shooting
## 26  Armando Broja Forwards               Shooting
## 27  Armando Broja Forwards               Shooting
## 28  Armando Broja Forwards               Shooting
## 29  Armando Broja Forwards               Shooting
## 31  Armando Broja Forwards               Shooting
## 32  Armando Broja Forwards               Shooting
## 33  Armando Broja Forwards               Shooting
## 34  Armando Broja Forwards               Shooting
## 35  Armando Broja Forwards               Shooting
## 38  Armando Broja Forwards                Passing
## 39  Armando Broja Forwards                Passing
## 40  Armando Broja Forwards                Passing
## 41  Armando Broja Forwards                Passing
## 42  Armando Broja Forwards                Passing
## 44  Armando Broja Forwards                Passing
## 45  Armando Broja Forwards                Passing
## 46  Armando Broja Forwards                Passing
## 48  Armando Broja Forwards                Passing
## 49  Armando Broja Forwards                Passing
## 50  Armando Broja Forwards                Passing
## 52  Armando Broja Forwards                Passing
## 53  Armando Broja Forwards                Passing
## 54  Armando Broja Forwards                Passing
## 55  Armando Broja Forwards                Passing
## 56  Armando Broja Forwards                Passing
## 57  Armando Broja Forwards                Passing
## 58  Armando Broja Forwards                Passing
## 59  Armando Broja Forwards                Passing
## 60  Armando Broja Forwards                Passing
## 61  Armando Broja Forwards                Passing
## 62  Armando Broja Forwards                Passing
## 65  Armando Broja Forwards             Pass Types
## 67  Armando Broja Forwards             Pass Types
## 68  Armando Broja Forwards             Pass Types
## 69  Armando Broja Forwards             Pass Types
## 70  Armando Broja Forwards             Pass Types
## 71  Armando Broja Forwards             Pass Types
## 72  Armando Broja Forwards             Pass Types
## 73  Armando Broja Forwards             Pass Types
## 74  Armando Broja Forwards             Pass Types
## 76  Armando Broja Forwards             Pass Types
## 77  Armando Broja Forwards             Pass Types
## 78  Armando Broja Forwards             Pass Types
## 80  Armando Broja Forwards             Pass Types
## 81  Armando Broja Forwards             Pass Types
## 82  Armando Broja Forwards             Pass Types
## 85  Armando Broja Forwards Goal and Shot Creation
## 87  Armando Broja Forwards Goal and Shot Creation
## 88  Armando Broja Forwards Goal and Shot Creation
## 89  Armando Broja Forwards Goal and Shot Creation
## 90  Armando Broja Forwards Goal and Shot Creation
## 91  Armando Broja Forwards Goal and Shot Creation
## 92  Armando Broja Forwards Goal and Shot Creation
## 94  Armando Broja Forwards Goal and Shot Creation
## 96  Armando Broja Forwards Goal and Shot Creation
## 97  Armando Broja Forwards Goal and Shot Creation
## 98  Armando Broja Forwards Goal and Shot Creation
## 99  Armando Broja Forwards Goal and Shot Creation
## 100 Armando Broja Forwards Goal and Shot Creation
## 101 Armando Broja Forwards Goal and Shot Creation
## 104 Armando Broja Forwards                Defense
## 105 Armando Broja Forwards                Defense
## 106 Armando Broja Forwards                Defense
## 107 Armando Broja Forwards                Defense
## 108 Armando Broja Forwards                Defense
## 110 Armando Broja Forwards                Defense
## 111 Armando Broja Forwards                Defense
## 112 Armando Broja Forwards                Defense
## 113 Armando Broja Forwards                Defense
## 115 Armando Broja Forwards                Defense
## 116 Armando Broja Forwards                Defense
## 117 Armando Broja Forwards                Defense
## 119 Armando Broja Forwards                Defense
## 120 Armando Broja Forwards                Defense
## 121 Armando Broja Forwards                Defense
## 122 Armando Broja Forwards                Defense
## 125 Armando Broja Forwards             Possession
## 126 Armando Broja Forwards             Possession
## 127 Armando Broja Forwards             Possession
## 128 Armando Broja Forwards             Possession
## 129 Armando Broja Forwards             Possession
## 130 Armando Broja Forwards             Possession
## 131 Armando Broja Forwards             Possession
## 133 Armando Broja Forwards             Possession
## 134 Armando Broja Forwards             Possession
## 135 Armando Broja Forwards             Possession
## 136 Armando Broja Forwards             Possession
## 137 Armando Broja Forwards             Possession
## 139 Armando Broja Forwards             Possession
## 140 Armando Broja Forwards             Possession
## 141 Armando Broja Forwards             Possession
## 143 Armando Broja Forwards             Possession
## 144 Armando Broja Forwards             Possession
## 145 Armando Broja Forwards             Possession
## 146 Armando Broja Forwards             Possession
## 147 Armando Broja Forwards             Possession
## 149 Armando Broja Forwards             Possession
## 150 Armando Broja Forwards             Possession
## 153 Armando Broja Forwards    Miscellaneous Stats
## 154 Armando Broja Forwards    Miscellaneous Stats
## 155 Armando Broja Forwards    Miscellaneous Stats
## 156 Armando Broja Forwards    Miscellaneous Stats
## 157 Armando Broja Forwards    Miscellaneous Stats
## 158 Armando Broja Forwards    Miscellaneous Stats
## 159 Armando Broja Forwards    Miscellaneous Stats
## 161 Armando Broja Forwards    Miscellaneous Stats
## 162 Armando Broja Forwards    Miscellaneous Stats
## 163 Armando Broja Forwards    Miscellaneous Stats
## 164 Armando Broja Forwards    Miscellaneous Stats
## 165 Armando Broja Forwards    Miscellaneous Stats
## 166 Armando Broja Forwards    Miscellaneous Stats
## 168 Armando Broja Forwards    Miscellaneous Stats
## 169 Armando Broja Forwards    Miscellaneous Stats
## 170 Armando Broja Forwards    Miscellaneous Stats
##                             Statistic  Per90 Percentile BasedOnMinutes
## 2                               Goals   0.27         42           1975
## 3                             Assists   0.00          5           1975
## 4                     Goals + Assists   0.27         14           1975
## 5                   Non-Penalty Goals   0.27         48           1975
## 6                  Penalty Kicks Made   0.00         32           1975
## 7             Penalty Kicks Attempted   0.00         30           1975
## 8                        Yellow Cards   0.09         70           1975
## 9                           Red Cards   0.00         55           1975
## 10                 xG: Expected Goals   0.27         30           1975
## 11               npxG: Non-Penalty xG   0.27         39           1975
## 12           xAG: Exp. Assisted Goals   0.05          6           1975
## 13                         npxG + xAG   0.31         19           1975
## 15                Progressive Carries   2.55         71           1975
## 16                 Progressive Passes   1.32         20           1975
## 17             Progressive Passes Rec   5.19         22           1975
## 20                              Goals   0.27         42           1975
## 21                        Shots Total   2.05         25           1975
## 22                    Shots on Target   0.87         53           1975
## 23                  Shots on Target %  42.20         80           1975
## 24                         Goals/Shot   0.13         63           1975
## 25               Goals/Shot on Target   0.32         52           1975
## 26              Average Shot Distance  13.00         84           1975
## 27              Shots from Free Kicks   0.00         39           1975
## 28                 Penalty Kicks Made   0.00         32           1975
## 29            Penalty Kicks Attempted   0.00         30           1975
## 31                 xG: Expected Goals   0.27         30           1975
## 32               npxG: Non-Penalty xG   0.27         39           1975
## 33                          npxG/Shot   0.13         48           1975
## 34                         Goals - xG   0.00         70           1975
## 35           Non-Penalty Goals - npxG   0.00         73           1975
## 38                   Passes Completed  11.07          7           1975
## 39                   Passes Attempted  18.41         16           1975
## 40                  Pass Completion %  60.10          9           1975
## 41             Total Passing Distance 118.21          4           1975
## 42       Progressive Passing Distance  26.07         14           1975
## 44           Passes Completed (Short)   7.61         14           1975
## 45           Passes Attempted (Short)  11.35         34           1975
## 46          Pass Completion % (Short)  67.10          7           1975
## 48          Passes Completed (Medium)   2.19          7           1975
## 49          Passes Attempted (Medium)   3.96         12           1975
## 50         Pass Completion % (Medium)  55.20          7           1975
## 52            Passes Completed (Long)   0.05          1           1975
## 53            Passes Attempted (Long)   0.32          4           1975
## 54           Pass Completion % (Long)  14.30          1           1975
## 55                            Assists   0.00          5           1975
## 56           xAG: Exp. Assisted Goals   0.05          6           1975
## 57               xA: Expected Assists   0.01          1           1975
## 58                         Key Passes   0.46          1           1975
## 59            Passes into Final Third   0.59         19           1975
## 60           Passes into Penalty Area   0.09          1           1975
## 61          Crosses into Penalty Area   0.00         16           1975
## 62                 Progressive Passes   1.32         20           1975
## 65                   Passes Attempted  18.41         16           1975
## 67                   Live-ball Passes  18.32         24           1975
## 68                   Dead-ball Passes   0.09          6           1975
## 69             Passes from Free Kicks   0.00         22           1975
## 70                      Through Balls   0.05         19           1975
## 71                           Switches   0.05         34           1975
## 72                            Crosses   0.36         29           1975
## 73                    Throw-ins Taken   0.00          8           1975
## 74                       Corner Kicks   0.00         37           1975
## 76            Inswinging Corner Kicks   0.00         40           1975
## 77           Outswinging Corner Kicks   0.00         42           1975
## 78              Straight Corner Kicks   0.00         48           1975
## 80                   Passes Completed  11.07          7           1975
## 81                     Passes Offside   0.00         92           1975
## 82                     Passes Blocked   0.59         78           1975
## 85              Shot-Creating Actions   1.73         11           1975
## 87               SCA (Live-ball Pass)   0.87          1           1975
## 88               SCA (Dead-ball Pass)   0.00         34           1975
## 89                      SCA (Take-On)   0.32         76           1975
## 90                         SCA (Shot)   0.32         61           1975
## 91                  SCA (Fouls Drawn)   0.18         40           1975
## 92             SCA (Defensive Action)   0.05         65           1975
## 94              Goal-Creating Actions   0.18         20           1975
## 96               GCA (Live-ball Pass)   0.00          3           1975
## 97               GCA (Dead-ball Pass)   0.00         44           1975
## 98                      GCA (Take-On)   0.09         86           1975
## 99                         GCA (Shot)   0.00         21           1975
## 100                 GCA (Fouls Drawn)   0.09         91           1975
## 101            GCA (Defensive Action)   0.00         44           1975
## 104                           Tackles   0.55         22           1975
## 105                       Tackles Won   0.23         16           1975
## 106                 Tackles (Def 3rd)   0.09         27           1975
## 107                 Tackles (Mid 3rd)   0.32         43           1975
## 108                 Tackles (Att 3rd)   0.14         24           1975
## 110                 Dribblers Tackled   0.09         17           1975
## 111               Dribbles Challenged   0.41         11           1975
## 112            % of Dribblers Tackled  22.20         35           1975
## 113                   Challenges Lost   0.32         86           1975
## 115                            Blocks   0.77         53           1975
## 116                     Shots Blocked   0.05         30           1975
## 117                    Passes Blocked   0.73         60           1975
## 119                     Interceptions   0.14         22           1975
## 120                           Tkl+Int   0.68         16           1975
## 121                        Clearances   0.50         40           1975
## 122                            Errors   0.00         54           1975
## 125                           Touches  30.67         24           1975
## 126                 Touches (Def Pen)   0.68         34           1975
## 127                 Touches (Def 3rd)   2.32         20           1975
## 128                 Touches (Mid 3rd)  12.67         25           1975
## 129                 Touches (Att 3rd)  16.41         42           1975
## 130                 Touches (Att Pen)   4.60         48           1975
## 131               Touches (Live-Ball)  30.67         24           1975
## 133                Take-Ons Attempted   3.19         81           1975
## 134               Successful Take-Ons   1.50         71           1975
## 135              Successful Take-On %  47.10         37           1975
## 136      Times Tackled During Take-On   1.69         17           1975
## 137 Tackled During Take-On Percentage  52.90         37           1975
## 139                           Carries  16.59         29           1975
## 140           Total Carrying Distance 111.51         50           1975
## 141     Progressive Carrying Distance  56.83         57           1975
## 143               Progressive Carries   2.55         71           1975
## 144          Carries into Final Third   1.28         58           1975
## 145         Carries into Penalty Area   1.50         84           1975
## 146                       Miscontrols   3.10         39           1975
## 147                      Dispossessed   2.28         11           1975
## 149                   Passes Received  22.24         29           1975
## 150            Progressive Passes Rec   5.19         22           1975
## 153                      Yellow Cards   0.09         70           1975
## 154                         Red Cards   0.00         55           1975
## 155                Second Yellow Card   0.00         53           1975
## 156                   Fouls Committed   1.32         30           1975
## 157                       Fouls Drawn   1.18         50           1975
## 158                          Offsides   0.59         42           1975
## 159                           Crosses   0.36         29           1975
## 161                     Interceptions   0.14         22           1975
## 162                       Tackles Won   0.23         16           1975
## 163                 Penalty Kicks Won   0.05         80           1975
## 164            Penalty Kicks Conceded   0.00         52           1975
## 165                         Own Goals   0.00         51           1975
## 166                   Ball Recoveries   3.69         70           1975
## 168                       Aerials Won   4.01         89           1975
## 169                      Aerials Lost   7.56          1           1975
## 170                  % of Aerials Won  34.60         45           1975
##              scouting_period index
## 2   2021-2022 Premier League   136
## 3   2021-2022 Premier League   137
## 4   2021-2022 Premier League   138
## 5   2021-2022 Premier League   139
## 6   2021-2022 Premier League   140
## 7   2021-2022 Premier League   141
## 8   2021-2022 Premier League   142
## 9   2021-2022 Premier League   143
## 10  2021-2022 Premier League   144
## 11  2021-2022 Premier League   145
## 12  2021-2022 Premier League   146
## 13  2021-2022 Premier League   147
## 15  2021-2022 Premier League   148
## 16  2021-2022 Premier League   149
## 17  2021-2022 Premier League   150
## 20  2021-2022 Premier League   151
## 21  2021-2022 Premier League   152
## 22  2021-2022 Premier League   153
## 23  2021-2022 Premier League   154
## 24  2021-2022 Premier League   155
## 25  2021-2022 Premier League   156
## 26  2021-2022 Premier League   157
## 27  2021-2022 Premier League   158
## 28  2021-2022 Premier League   159
## 29  2021-2022 Premier League   160
## 31  2021-2022 Premier League   161
## 32  2021-2022 Premier League   162
## 33  2021-2022 Premier League   163
## 34  2021-2022 Premier League   164
## 35  2021-2022 Premier League   165
## 38  2021-2022 Premier League   166
## 39  2021-2022 Premier League   167
## 40  2021-2022 Premier League   168
## 41  2021-2022 Premier League   169
## 42  2021-2022 Premier League   170
## 44  2021-2022 Premier League   171
## 45  2021-2022 Premier League   172
## 46  2021-2022 Premier League   173
## 48  2021-2022 Premier League   174
## 49  2021-2022 Premier League   175
## 50  2021-2022 Premier League   176
## 52  2021-2022 Premier League   177
## 53  2021-2022 Premier League   178
## 54  2021-2022 Premier League   179
## 55  2021-2022 Premier League   180
## 56  2021-2022 Premier League   181
## 57  2021-2022 Premier League   182
## 58  2021-2022 Premier League   183
## 59  2021-2022 Premier League   184
## 60  2021-2022 Premier League   185
## 61  2021-2022 Premier League   186
## 62  2021-2022 Premier League   187
## 65  2021-2022 Premier League   188
## 67  2021-2022 Premier League   189
## 68  2021-2022 Premier League   190
## 69  2021-2022 Premier League   191
## 70  2021-2022 Premier League   192
## 71  2021-2022 Premier League   193
## 72  2021-2022 Premier League   194
## 73  2021-2022 Premier League   195
## 74  2021-2022 Premier League   196
## 76  2021-2022 Premier League   197
## 77  2021-2022 Premier League   198
## 78  2021-2022 Premier League   199
## 80  2021-2022 Premier League   200
## 81  2021-2022 Premier League   201
## 82  2021-2022 Premier League   202
## 85  2021-2022 Premier League   203
## 87  2021-2022 Premier League   204
## 88  2021-2022 Premier League   205
## 89  2021-2022 Premier League   206
## 90  2021-2022 Premier League   207
## 91  2021-2022 Premier League   208
## 92  2021-2022 Premier League   209
## 94  2021-2022 Premier League   210
## 96  2021-2022 Premier League   211
## 97  2021-2022 Premier League   212
## 98  2021-2022 Premier League   213
## 99  2021-2022 Premier League   214
## 100 2021-2022 Premier League   215
## 101 2021-2022 Premier League   216
## 104 2021-2022 Premier League   217
## 105 2021-2022 Premier League   218
## 106 2021-2022 Premier League   219
## 107 2021-2022 Premier League   220
## 108 2021-2022 Premier League   221
## 110 2021-2022 Premier League   222
## 111 2021-2022 Premier League   223
## 112 2021-2022 Premier League   224
## 113 2021-2022 Premier League   225
## 115 2021-2022 Premier League   226
## 116 2021-2022 Premier League   227
## 117 2021-2022 Premier League   228
## 119 2021-2022 Premier League   229
## 120 2021-2022 Premier League   230
## 121 2021-2022 Premier League   231
## 122 2021-2022 Premier League   232
## 125 2021-2022 Premier League   233
## 126 2021-2022 Premier League   234
## 127 2021-2022 Premier League   235
## 128 2021-2022 Premier League   236
## 129 2021-2022 Premier League   237
## 130 2021-2022 Premier League   238
## 131 2021-2022 Premier League   239
## 133 2021-2022 Premier League   240
## 134 2021-2022 Premier League   241
## 135 2021-2022 Premier League   242
## 136 2021-2022 Premier League   243
## 137 2021-2022 Premier League   244
## 139 2021-2022 Premier League   245
## 140 2021-2022 Premier League   246
## 141 2021-2022 Premier League   247
## 143 2021-2022 Premier League   248
## 144 2021-2022 Premier League   249
## 145 2021-2022 Premier League   250
## 146 2021-2022 Premier League   251
## 147 2021-2022 Premier League   252
## 149 2021-2022 Premier League   253
## 150 2021-2022 Premier League   254
## 153 2021-2022 Premier League   255
## 154 2021-2022 Premier League   256
## 155 2021-2022 Premier League   257
## 156 2021-2022 Premier League   258
## 157 2021-2022 Premier League   259
## 158 2021-2022 Premier League   260
## 159 2021-2022 Premier League   261
## 161 2021-2022 Premier League   262
## 162 2021-2022 Premier League   263
## 163 2021-2022 Premier League   264
## 164 2021-2022 Premier League   265
## 165 2021-2022 Premier League   266
## 166 2021-2022 Premier League   267
## 168 2021-2022 Premier League   268
## 169 2021-2022 Premier League   269
## 170 2021-2022 Premier League   270

As you can see, there are a lot of variables to choose from. That is why the index was created, so that we can have a reference to what type of variables that you want to analyse.

Let’s have a look at some statistics combinations from the database

Filter Database to select specific variables

Armando_Broja_filter <- Armando_Broja[c(151,152,153,154,249,250,251,252,253,254,237,238,217,229),]

Now that we have selected our variables, let’s actually plot Armando’s statistics in a pizza plot

Pizza Plot

#Pizza Plot for Armando Broja

plot_pizza(data = Armando_Broja_filter, #load the database
                       type = "single", 
                       template = "outfielder", 
                       color_possession = "#41ab5d", #change color of the stat type
                       color_attack = "#fec44f", 
                       color_defense = "#de2d26",
                       season = "2021-2022 Premier League", #You can filter through different seasons
                       theme = "white") #You can filter through different themes

As you can see from the plot above, some of the variables that we selected aren’t actually appearing in the pizza plot, that is because we are using the given template that the function has given us.

To actually customize it and use the variables that we want to view, we have to change the template of the function to “custom”.

plot_pizza(data = Armando_Broja_filter, #load the database
                       type = "single", 
                       template = "custom", 
                       color_possession = "#41ab5d", #change color of the stat type
                       color_attack = "#fec44f", 
                       color_defense = "#de2d26",
                       season = "2021-2022 Premier League", #You can filter through different seasons
                       theme = "white") #You can filter through different themes