# Load Packages:
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── 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
library(ggplot2) # Load ggplot2
library(ggdark) # Load ggdark
library(ggimage) # Load ggimage
library(reshape) # Load reshape
## 
## Attaching package: 'reshape'
## 
## The following object is masked from 'package:lubridate':
## 
##     stamp
## 
## The following object is masked from 'package:dplyr':
## 
##     rename
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, smiths
library(ggridges) # Load ggridges
library(ggrepel) # Load ggrepellibrary(tidyverse) # Load tidyverse
library(GGally) # Load GGally
## Warning: package 'GGally' was built under R version 4.3.2
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
# Load Functions:
source("sports_analytics_functions.r")
#source("pbp_functions.r")
load("team_logos.rda")
library(cfbfastR)
# Load data
cfb_2023 <- load_cfb_pbp(seasons = 2023, weeks = c(1, 2, 3,4,5,6,7,8,9,10,11))
class(cfb_2023)
## [1] "cfbfastR_data" "tbl_df"        "tbl"           "data.table"   
## [5] "data.frame"
# Convert to data frame
cfb_2023 <- as.data.frame(cfb_2023)
# Create summarized play type
s_play_type <- create_simplex_play_type(cfb_2023)
# Add summarized play type back to dataset
cfb_2023$playtype <- s_play_type
# Create team level summary
team_summary <- create_team_summary(pbp = cfb_2023, # Set dataset
                                team_logos = team_logos) # Set logos to 

The first few columns relate to team level information

The next few columns relate to the offensive performance of the school:

We then have the offensive statistics at a per play level:

The next set of columns relate to the defensive performance of the school:

Finally we have the defensive statistics at a per play level:

CFP_schools <- team_summary %>%
  filter(school %in% c('Washington', 'Ohio State', 'Michigan','Florida State', 'Georgia'))

CFP_schools
##   team_id        school   color alt_color
## 1      52 Florida State #782F40   #ceb888
## 2      61       Georgia #CC0000   #000000
## 3     130      Michigan #00274c   #00274c
## 4     194    Ohio State #DE3121   #666666
## 5     264    Washington #2B2F64   #e8e3d3
##                                               logos games pass_n pass_yards
## 1  http://a.espncdn.com/i/teamlogos/ncaa/500/52.png    14    450       3386
## 2  http://a.espncdn.com/i/teamlogos/ncaa/500/61.png    14    458       4191
## 3 http://a.espncdn.com/i/teamlogos/ncaa/500/130.png    15    375       3033
## 4 http://a.espncdn.com/i/teamlogos/ncaa/500/194.png    13    406       3435
## 5 http://a.espncdn.com/i/teamlogos/ncaa/500/264.png    15    564       4984
##    pass_epa pass_wpa rush_n rush_yards  rush_epa   rush_wpa pass_yards_per_play
## 1  79.63176 2.003827    430       2352  5.583882 -0.3031046            7.524444
## 2 189.34201 4.208871    480       2763 84.793574  1.4547209            9.150655
## 3 139.01841 3.180742    535       2679 16.143942  1.1494568            8.088000
## 4 141.76881 4.375914    407       2026  2.305381 -0.2555346            8.460591
## 5 205.74318 5.030551    392       1895 41.021508  1.6135143            8.836879
##   pass_epa_per_play pass_wpa_per_play rush_yards_per_play rush_epa_per_play
## 1         0.1769595       0.004452949            5.469767       0.012985773
## 2         0.4134105       0.009189674            5.756250       0.176653280
## 3         0.3707158       0.008481979            5.007477       0.030175593
## 4         0.3491843       0.010778113            4.977887       0.005664326
## 5         0.3647929       0.008919416            4.834184       0.104646704
##   rush_wpa_per_play pass_n_def pass_yards_def pass_epa_def pass_wpa_def
## 1     -0.0007048944        443           2276    -52.17071   -1.4578405
## 2      0.0030306685        438           2312    -46.31946   -0.6245065
## 3      0.0021485174        429           2329    -47.65445   -0.5731249
## 4     -0.0006278491        397           1980    -67.20990   -1.5137899
## 5      0.0041161079        577           3827     39.04008    0.0787014
##   rush_n_def rush_yards_def rush_epa_def rush_wpa_def pass_yards_per_play_def
## 1        457           2495     27.37214    0.3183271                5.137698
## 2        386           1831     23.78378    0.9826433                5.278539
## 3        399           1636    -40.28552   -0.9973048                5.428904
## 4        414           1798    -23.84612   -0.5046498                4.987406
## 5        441           2437     79.85563    1.9417721                6.632582
##   pass_epa_per_play_def pass_wpa_per_play_def rush_yards_per_play_def
## 1           -0.11776685         -0.0032908363                5.459519
## 2           -0.10575218         -0.0014258139                4.743523
## 3           -0.11108263         -0.0013359555                4.100251
## 4           -0.16929446         -0.0038130728                4.342995
## 5            0.06766044          0.0001363976                5.526077
##   rush_epa_per_play_def rush_wpa_per_play_def
## 1            0.05989526          0.0006965582
## 2            0.06161601          0.0025457080
## 3           -0.10096622         -0.0024995108
## 4           -0.05759932         -0.0012189609
## 5            0.18107854          0.0044031113

Power Five Opponents

wash_opponents <- team_summary %>%
  filter(school %in% c('Michigan State', 'Colorado', 'Arizona', 'Oregon','Arizona State','Stanford', 'USC', 'Utah'))
wash_opponents
##   team_id         school   color alt_color
## 1      12        Arizona #002449   #00205b
## 2       9  Arizona State #942139   #f1f2f3
## 3      38       Colorado #d1c57e   #ffd200
## 4     127 Michigan State #18453B   #ffffff
## 5    2483         Oregon #044520   #fee123
## 6      24       Stanford #A80532   #ffffff
## 7      30            USC #ffc72c   #ae2531
## 8     254           Utah #890012   #7e8083
##                                                logos games pass_n pass_yards
## 1   http://a.espncdn.com/i/teamlogos/ncaa/500/12.png    13    472       3801
## 2    http://a.espncdn.com/i/teamlogos/ncaa/500/9.png    12    443       2567
## 3   http://a.espncdn.com/i/teamlogos/ncaa/500/38.png    12    515       3141
## 4  http://a.espncdn.com/i/teamlogos/ncaa/500/127.png    12    382       2233
## 5 http://a.espncdn.com/i/teamlogos/ncaa/500/2483.png    14    513       4867
## 6   http://a.espncdn.com/i/teamlogos/ncaa/500/24.png    11    422       2373
## 7   http://a.espncdn.com/i/teamlogos/ncaa/500/30.png    13    475       4097
## 8  http://a.espncdn.com/i/teamlogos/ncaa/500/254.png    13    336       1977
##      pass_epa   pass_wpa rush_n rush_yards    rush_epa   rush_wpa
## 1 163.7452103  4.2541334    366       2060  27.1088141  1.1596285
## 2 -51.3529614 -1.2573172    336       1610  41.7053233  1.6524613
## 3  69.5076706  1.6258708    295       1340   3.1291100 -0.6845427
## 4   2.7956544  0.4959752    338       1331 -37.0184722 -1.3528307
## 5 247.1245444  4.7180691    426       2635  93.8840557  2.1893922
## 6  -9.7483546 -0.8777989    324       1422   1.2375901 -0.9122083
## 7 179.7369429  4.5514674    320       2069  69.5613929  2.0888405
## 8  -0.4753251  0.6590489    526       2580  -0.6045823  1.0200754
##   pass_yards_per_play pass_epa_per_play pass_wpa_per_play rush_yards_per_play
## 1            8.052966       0.346917818       0.009012994            5.628415
## 2            5.794582      -0.115920906      -0.002838188            4.791667
## 3            6.099029       0.134966351       0.003157031            4.542373
## 4            5.845550       0.007318467       0.001298364            3.937870
## 5            9.487329       0.481724258       0.009197016            6.185446
## 6            5.623223      -0.023100366      -0.002080092            4.388889
## 7            8.625263       0.378393564       0.009582037            6.465625
## 8            5.883929      -0.001414658       0.001961455            4.904943
##   rush_epa_per_play rush_wpa_per_play pass_n_def pass_yards_def pass_epa_def
## 1       0.074067798       0.003168384        441           2831     57.42390
## 2       0.124122986       0.004918040        426           3003     89.60483
## 3       0.010607153      -0.002320484        427           3224     96.95200
## 4      -0.109522107      -0.004002458        381           2635     37.08543
## 5       0.220385107       0.005139418        509           2783    -16.36361
## 6       0.003819723      -0.002815458        406           3145    107.52211
## 7       0.217379353       0.006527627        433           3052     99.98367
## 8      -0.001149396       0.001939307        449           2691    -18.19337
##   pass_wpa_def rush_n_def rush_yards_def rush_epa_def rush_wpa_def
## 1    1.5732988        373           1801    -9.027035   -0.1069329
## 2    2.2552867        341           1915    35.921451    0.7295600
## 3    1.4428285        410           2205    54.856533    2.1513972
## 4   -0.7545207        399           2006    20.835010    1.1275698
## 5    0.3886522        363           1711     8.604234    0.2114477
## 6    1.6715455        355           1966    48.803993    1.6862894
## 7    2.4069297        459           2693    87.520814    2.5605795
## 8   -0.0449772        304           1402    -1.882643    0.3504192
##   pass_yards_per_play_def pass_epa_per_play_def pass_wpa_per_play_def
## 1                6.419501            0.13021293          0.0035675710
## 2                7.049296            0.21033999          0.0052941002
## 3                7.550351            0.22705386          0.0033789895
## 4                6.916010            0.09733709         -0.0019803693
## 5                5.467583           -0.03214855          0.0007635603
## 6                7.746305            0.26483277          0.0041171071
## 7                7.048499            0.23090916          0.0055587291
## 8                5.993318           -0.04051976         -0.0001001719
##   rush_yards_per_play_def rush_epa_per_play_def rush_wpa_per_play_def
## 1                4.828418          -0.024201166         -0.0002866834
## 2                5.615836           0.105341500          0.0021394721
## 3                5.378049           0.133796421          0.0052473102
## 4                5.027569           0.052218069          0.0028259895
## 5                4.713499           0.023703124          0.0005825006
## 6                5.538028           0.137476038          0.0047501110
## 7                5.867102           0.190677155          0.0055786046
## 8                4.611842          -0.006192906          0.0011526947
osu_opponents <- team_summary %>%
  filter(school %in% c('Indiana', 'Notre Dame', 'Maryland', 'Purdue', 'Penn State', 'Wisconsin', 'Rutgers', 'Michigan State'))
osu_opponents
##   team_id         school   color alt_color
## 1      84        Indiana #7D110C   #eeedeb
## 2     120       Maryland #D5002B   #ffcd00
## 3     127 Michigan State #18453B   #ffffff
## 4      87     Notre Dame #00122b   #ae9142
## 5     213     Penn State #00265D   #002e5c
## 6    2509         Purdue #B89D29   #a4a9ad
## 7     164        Rutgers #d21034   #ffffff
## 8     275      Wisconsin #A00001   #f7f7f7
##                                                logos games pass_n pass_yards
## 1   http://a.espncdn.com/i/teamlogos/ncaa/500/84.png    12    375       2459
## 2  http://a.espncdn.com/i/teamlogos/ncaa/500/120.png    13    476       3412
## 3  http://a.espncdn.com/i/teamlogos/ncaa/500/127.png    12    382       2233
## 4   http://a.espncdn.com/i/teamlogos/ncaa/500/87.png    13    355       3130
## 5  http://a.espncdn.com/i/teamlogos/ncaa/500/213.png    12    389       2330
## 6 http://a.espncdn.com/i/teamlogos/ncaa/500/2509.png    12    399       2347
## 7  http://a.espncdn.com/i/teamlogos/ncaa/500/164.png    13    301       1958
## 8  http://a.espncdn.com/i/teamlogos/ncaa/500/275.png    13    475       2729
##     pass_epa   pass_wpa rush_n rush_yards   rush_epa   rush_wpa
## 1  42.855980  0.2835486    392       1836   5.224981 -0.8447534
## 2  83.068516  2.6174819    346       1645  29.669067 -0.2415450
## 3   2.795654  0.4959752    338       1331 -37.018472 -1.3528307
## 4 134.206582  2.4279823    435       2573  38.391903  1.8447991
## 5  48.808517  0.4778306    455       2380  42.948959  0.2992406
## 6  32.591094  0.9408402    426       2241  14.012259  0.4913417
## 7 -16.622177 -0.3852609    497       2313  29.660547  0.7518497
## 8  15.817574  0.7475566    420       2293  47.420880  0.4374948
##   pass_yards_per_play pass_epa_per_play pass_wpa_per_play rush_yards_per_play
## 1            6.557333       0.114282613      0.0007561296            4.683673
## 2            7.168067       0.174513689      0.0054989116            4.754335
## 3            5.845550       0.007318467      0.0012983644            3.937870
## 4            8.816901       0.378046711      0.0068393868            5.914943
## 5            5.989717       0.125471765      0.0012283563            5.230769
## 6            5.882206       0.081681939      0.0023579955            5.260563
## 7            6.504983      -0.055223179     -0.0012799365            4.653924
## 8            5.745263       0.033300156      0.0015738034            5.459524
##   rush_epa_per_play rush_wpa_per_play pass_n_def pass_yards_def pass_epa_def
## 1        0.01332903     -0.0021549832        369           2760    93.559239
## 2        0.08574875     -0.0006981069        429           2584     5.742464
## 3       -0.10952211     -0.0040024577        381           2635    37.085431
## 4        0.08825725      0.0042409175        381           1907   -51.289119
## 5        0.09439332      0.0006576716        338           1748    -4.934523
## 6        0.03289263      0.0011533843        387           2669    60.131581
## 7        0.05967917      0.0015127761        376           2195     4.062885
## 8        0.11290686      0.0010416543        423           2626    30.265027
##   pass_wpa_def rush_n_def rush_yards_def rush_epa_def rush_wpa_def
## 1    3.2615373        414           2133     14.73867    0.7306050
## 2    0.5858409        435           1892     34.43923    0.4462835
## 3   -0.7545207        399           2006     20.83501    1.1275698
## 4    0.0792963        394           1771    -20.60773   -0.5983444
## 5    0.6914861        336           1205    -51.96237   -0.8635065
## 6    2.2998618        388           2021     11.63151    0.4993871
## 7    0.4031184        414           1929     10.61268    0.1963823
## 8    1.1746766        421           2019    -11.19810   -0.0763232
##   pass_yards_per_play_def pass_epa_per_play_def pass_wpa_per_play_def
## 1                7.479675            0.25354807          0.0088388545
## 2                6.023310            0.01338570          0.0013655965
## 3                6.916010            0.09733709         -0.0019803693
## 4                5.005249           -0.13461711          0.0002081268
## 5                5.171598           -0.01459918          0.0020458169
## 6                6.896641            0.15537876          0.0059427953
## 7                5.837766            0.01080555          0.0010721234
## 8                6.208038            0.07154853          0.0027770132
##   rush_yards_per_play_def rush_epa_per_play_def rush_wpa_per_play_def
## 1                5.152174            0.03560066          0.0017647464
## 2                4.349425            0.07917064          0.0010259391
## 3                5.027569            0.05221807          0.0028259895
## 4                4.494924           -0.05230387         -0.0015186406
## 5                3.586310           -0.15464991         -0.0025699598
## 6                5.208763            0.02997812          0.0012870802
## 7                4.659420            0.02563450          0.0004743534
## 8                4.795724           -0.02659882         -0.0001812903
uga_opponents <- team_summary %>%
  filter(school %in% c('South Carolina', 'Auburn', 'Kentucky', 'Vanderbilt', 'Florida','Missouri', 'Ole Miss'))
uga_opponents
##   team_id         school   color alt_color
## 1       2         Auburn #03244d   #f1f2f3
## 2      57        Florida #0021A5   #0021a5
## 3      96       Kentucky #005DAA   #ffffff
## 4     142       Missouri #000000   #000000
## 5     145       Ole Miss #001148   #00205b
## 6    2579 South Carolina #670010   #000000
## 7     238     Vanderbilt #000000   #231f20
##                                                logos games pass_n pass_yards
## 1    http://a.espncdn.com/i/teamlogos/ncaa/500/2.png    13    339       2003
## 2   http://a.espncdn.com/i/teamlogos/ncaa/500/57.png    12    407       2911
## 3   http://a.espncdn.com/i/teamlogos/ncaa/500/96.png    13    378       2440
## 4  http://a.espncdn.com/i/teamlogos/ncaa/500/142.png    13    389       3162
## 5  http://a.espncdn.com/i/teamlogos/ncaa/500/145.png    12    391       3303
## 6 http://a.espncdn.com/i/teamlogos/ncaa/500/2579.png    12    444       3135
## 7  http://a.espncdn.com/i/teamlogos/ncaa/500/238.png    12    400       2600
##      pass_epa   pass_wpa rush_n rush_yards rush_epa   rush_wpa
## 1   3.5927653 -0.0089103    470       2648 29.27564  0.7364704
## 2 104.2608333  2.9074054    376       2098 32.08914  0.7722525
## 3  45.7741313  1.9951784    306       1804 26.70193  0.3012614
## 4 105.5371900  4.0486876    463       2446 43.93006  1.9481411
## 5 121.3350966  2.8944055    465       2219 17.93317  0.6647422
## 6  74.0739394  1.8910716    317       1483 12.24418 -1.0478574
## 7  -0.6551529 -0.4689556    311       1407 -7.74191 -0.5774250
##   pass_yards_per_play pass_epa_per_play pass_wpa_per_play rush_yards_per_play
## 1            5.908555       0.010598128     -2.628407e-05            5.634043
## 2            7.152334       0.256169124      7.143502e-03            5.579787
## 3            6.455026       0.121095585      5.278250e-03            5.895425
## 4            8.128535       0.271303830      1.040794e-02            5.282937
## 5            8.447570       0.310319940      7.402572e-03            4.772043
## 6            7.060811       0.166833197      4.259170e-03            4.678233
## 7            6.500000      -0.001637882     -1.172389e-03            4.524116
##   rush_epa_per_play rush_wpa_per_play pass_n_def pass_yards_def pass_epa_def
## 1        0.06228859      0.0015669583        374           2474     38.52711
## 2        0.08534346      0.0020538630        340           2509     60.08365
## 3        0.08726120      0.0009845144        449           2984     65.66916
## 4        0.09488135      0.0042076482        429           2552     52.41314
## 5        0.03856595      0.0014295531        381           2421     26.08508
## 6        0.03862517     -0.0033055438        407           2973     63.80615
## 7       -0.02489360     -0.0018566720        425           3219    108.84189
##   pass_wpa_def rush_n_def rush_yards_def rush_epa_def rush_wpa_def
## 1    1.9806916        423           2196    27.602216    0.0969768
## 2    2.8671847        352           2053    24.937871    1.0468614
## 3    2.0971901        407           1745    -7.811984    0.6621678
## 4    1.6514378        371           1858     1.588434    0.0426262
## 5    1.1525432        407           2131    34.178963    0.2810254
## 6    0.8648528        432           2026    44.811431   -1.6099034
## 7    2.8882172        384           2299    46.592902    1.3234070
##   pass_yards_per_play_def pass_epa_per_play_def pass_wpa_per_play_def
## 1                6.614973            0.10301366           0.005295967
## 2                7.379412            0.17671663           0.008432896
## 3                6.645880            0.14625648           0.004670802
## 4                5.948718            0.12217515           0.003849505
## 5                6.354331            0.06846478           0.003025048
## 6                7.304668            0.15677186           0.002124945
## 7                7.574118            0.25609857           0.006795805
##   rush_yards_per_play_def rush_epa_per_play_def rush_wpa_per_play_def
## 1                5.191489           0.065253465          0.0002292596
## 2                5.832386           0.070846226          0.0029740381
## 3                4.287469          -0.019194065          0.0016269479
## 4                5.008086           0.004281495          0.0001148954
## 5                5.235872           0.083977797          0.0006904801
## 6                4.689815           0.103730164         -0.0037266282
## 7                5.986979           0.121335681          0.0034463724
fsu_opponents <- team_summary %>%
  filter(school %in% c('Louisiana', 'Boston College', 'Clemson','Virginia Tech', 'Syracuse', 'Duke', 'Wake Forest', 'Pittsburgh','Miami'))
fsu_opponents
##   team_id         school   color alt_color
## 1     103 Boston College #88001a   #a39161
## 2     228        Clemson #F66733   #522d80
## 3     150           Duke #001A57   #f1f2f3
## 4     309      Louisiana #ce2842      <NA>
## 5    2390          Miami #004325   #f0f0f0
## 6     221     Pittsburgh #003263   #231f20
## 7     183       Syracuse #F37321   #0d1d37
## 8     259  Virginia Tech #74232D   #c2c1ba
## 9     154    Wake Forest #9E7E38   #000000
##                                                logos games pass_n pass_yards
## 1  http://a.espncdn.com/i/teamlogos/ncaa/500/103.png    13    359       2202
## 2  http://a.espncdn.com/i/teamlogos/ncaa/500/228.png    13    485       2956
## 3  http://a.espncdn.com/i/teamlogos/ncaa/500/150.png    13    354       2237
## 4  http://a.espncdn.com/i/teamlogos/ncaa/500/309.png    13    370       2688
## 5 http://a.espncdn.com/i/teamlogos/ncaa/500/2390.png    13    434       3277
## 6  http://a.espncdn.com/i/teamlogos/ncaa/500/221.png    12    366       2383
## 7  http://a.espncdn.com/i/teamlogos/ncaa/500/183.png    12    288       1782
## 8  http://a.espncdn.com/i/teamlogos/ncaa/500/259.png    13    369       2461
## 9  http://a.espncdn.com/i/teamlogos/ncaa/500/154.png    11    322       2137
##    pass_epa  pass_wpa rush_n rush_yards   rush_epa   rush_wpa
## 1 47.063330 0.3226550    520       2756  95.269393  3.4423831
## 2 34.046045 0.5385697    472       2596  53.783089  1.7223772
## 3 30.902102 0.9344230    417       2232  11.213431  1.2847135
## 4 75.903576 1.1449934    428       2543  69.862917  0.3186995
## 5 87.307558 1.6291360    412       2266  29.733481  0.0371770
## 6  1.184086 0.6618310    321       1448 -10.191935 -0.2472961
## 7 19.389329 0.6181201    455       2211   6.898684  0.9796843
## 8 38.304219 1.1037903    454       2636  46.149935  0.8658242
## 9 21.949759 2.0281752    394       1863 -22.504778 -1.0617840
##   pass_yards_per_play pass_epa_per_play pass_wpa_per_play rush_yards_per_play
## 1            6.133705       0.131095626      0.0008987604            5.300000
## 2            6.094845       0.070198030      0.0011104530            5.500000
## 3            6.319209       0.087294073      0.0026396130            5.352518
## 4            7.264865       0.205144800      0.0030945768            5.941589
## 5            7.550691       0.201169489      0.0037537696            5.500000
## 6            6.510929       0.003235208      0.0018082814            4.510903
## 7            6.187500       0.067324060      0.0021462503            4.859341
## 8            6.669377       0.103805472      0.0029913016            5.806167
## 9            6.636646       0.068166953      0.0062986807            4.728426
##   rush_epa_per_play rush_wpa_per_play pass_n_def pass_yards_def pass_epa_def
## 1        0.18321037      6.619967e-03        340           2648     80.62896
## 2        0.11394722      3.649104e-03        414           2248    -60.46493
## 3        0.02689072      3.080848e-03        429           2580     25.79693
## 4        0.16323111      7.446250e-04        400           2762     58.81089
## 5        0.07216864      9.023544e-05        410           2627     47.06131
## 6       -0.03175057     -7.703928e-04        328           2456     34.20200
## 7        0.01516194      2.153152e-03        390           2786     25.40558
## 8        0.10165184      1.907102e-03        367           2009     33.84363
## 9       -0.05711873     -2.694883e-03        343           2542     70.77551
##   pass_wpa_def rush_n_def rush_yards_def rush_epa_def rush_wpa_def
## 1    0.7101673        441           2440   40.1142676    1.2121558
## 2   -2.4366942        349           1648   16.2540541    0.3574272
## 3    2.1720508        425           2029    1.8873242    0.8247876
## 4    1.0678048        530           2533   91.3787846    1.9303346
## 5    0.9288678        362           1601   -1.6511153    0.2910258
## 6    1.6736062        450           2092  -17.9618454    0.3722655
## 7    0.3587446        427           1868  -12.5084280    0.4988938
## 8    0.1997725        411           2229   14.1125049    0.7327847
## 9    2.5333820        362           1786    0.8516448   -0.4274775
##   pass_yards_per_play_def pass_epa_per_play_def pass_wpa_per_play_def
## 1                7.788235            0.23714401          0.0020887274
## 2                5.429952           -0.14605055         -0.0058857348
## 3                6.013986            0.06013270          0.0050630555
## 4                6.905000            0.14702721          0.0026695120
## 5                6.407317            0.11478369          0.0022655312
## 6                7.487805            0.10427439          0.0051024579
## 7                7.143590            0.06514251          0.0009198579
## 8                5.474114            0.09221696          0.0005443392
## 9                7.411079            0.20634260          0.0073859534
##   rush_yards_per_play_def rush_epa_per_play_def rush_wpa_per_play_def
## 1                5.532880           0.090962058          0.0027486526
## 2                4.722063           0.046573221          0.0010241467
## 3                4.774118           0.004440763          0.0019406767
## 4                4.779245           0.172412801          0.0036421408
## 5                4.422652          -0.004561092          0.0008039387
## 6                4.648889          -0.039915212          0.0008272567
## 7                4.374707          -0.029293742          0.0011683696
## 8                5.423358           0.034336995          0.0017829311
## 9                4.933702           0.002352610         -0.0011808771
mich_opponents <- team_summary %>%
  filter(school %in% c('Rutgers', 'Nebraska', 'Minnesota','Indiana', 'Michigan State', 'Purdue', 'Penn State'))
mich_opponents
##   team_id         school   color alt_color
## 1      84        Indiana #7D110C   #eeedeb
## 2     127 Michigan State #18453B   #ffffff
## 3     135      Minnesota #981a31   #981a31
## 4     158       Nebraska #F20017   #f5f1e7
## 5     213     Penn State #00265D   #002e5c
## 6    2509         Purdue #B89D29   #a4a9ad
## 7     164        Rutgers #d21034   #ffffff
##                                                logos games pass_n pass_yards
## 1   http://a.espncdn.com/i/teamlogos/ncaa/500/84.png    12    375       2459
## 2  http://a.espncdn.com/i/teamlogos/ncaa/500/127.png    12    382       2233
## 3  http://a.espncdn.com/i/teamlogos/ncaa/500/135.png    13    322       1770
## 4  http://a.espncdn.com/i/teamlogos/ncaa/500/158.png    12    264       1459
## 5  http://a.espncdn.com/i/teamlogos/ncaa/500/213.png    12    389       2330
## 6 http://a.espncdn.com/i/teamlogos/ncaa/500/2509.png    12    399       2347
## 7  http://a.espncdn.com/i/teamlogos/ncaa/500/164.png    13    301       1958
##     pass_epa   pass_wpa rush_n rush_yards   rush_epa   rush_wpa
## 1  42.855980  0.2835486    392       1836   5.224981 -0.8447534
## 2   2.795654  0.4959752    338       1331 -37.018472 -1.3528307
## 3 -17.021818 -0.5859017    473       2191  12.003562  0.0620768
## 4  -4.490151 -0.4148868    421       2405  57.185653  0.7979735
## 5  48.808517  0.4778306    455       2380  42.948959  0.2992406
## 6  32.591094  0.9408402    426       2241  14.012259  0.4913417
## 7 -16.622177 -0.3852609    497       2313  29.660547  0.7518497
##   pass_yards_per_play pass_epa_per_play pass_wpa_per_play rush_yards_per_play
## 1            6.557333       0.114282613      0.0007561296            4.683673
## 2            5.845550       0.007318467      0.0012983644            3.937870
## 3            5.496894      -0.052862788     -0.0018195705            4.632135
## 4            5.526515      -0.017008146     -0.0015715409            5.712589
## 5            5.989717       0.125471765      0.0012283563            5.230769
## 6            5.882206       0.081681939      0.0023579955            5.260563
## 7            6.504983      -0.055223179     -0.0012799365            4.653924
##   rush_epa_per_play rush_wpa_per_play pass_n_def pass_yards_def pass_epa_def
## 1        0.01332903     -0.0021549832        369           2760    93.559239
## 2       -0.10952211     -0.0040024577        381           2635    37.085431
## 3        0.02537751      0.0001312406        404           2623    54.663625
## 4        0.13583290      0.0018954240        422           2283     6.191926
## 5        0.09439332      0.0006576716        338           1748    -4.934523
## 6        0.03289263      0.0011533843        387           2669    60.131581
## 7        0.05967917      0.0015127761        376           2195     4.062885
##   pass_wpa_def rush_n_def rush_yards_def rush_epa_def rush_wpa_def
## 1    3.2615373        414           2133     14.73867    0.7306050
## 2   -0.7545207        399           2006     20.83501    1.1275698
## 3    0.2713660        385           2060     31.44874    1.0078924
## 4   -0.8903376        326           1438    -36.09389   -1.6787806
## 5    0.6914861        336           1205    -51.96237   -0.8635065
## 6    2.2998618        388           2021     11.63151    0.4993871
## 7    0.4031184        414           1929     10.61268    0.1963823
##   pass_yards_per_play_def pass_epa_per_play_def pass_wpa_per_play_def
## 1                7.479675            0.25354807           0.008838854
## 2                6.916010            0.09733709          -0.001980369
## 3                6.492574            0.13530600           0.000671698
## 4                5.409953            0.01467281          -0.002109805
## 5                5.171598           -0.01459918           0.002045817
## 6                6.896641            0.15537876           0.005942795
## 7                5.837766            0.01080555           0.001072123
##   rush_yards_per_play_def rush_epa_per_play_def rush_wpa_per_play_def
## 1                5.152174            0.03560066          0.0017647464
## 2                5.027569            0.05221807          0.0028259895
## 3                5.350649            0.08168504          0.0026179023
## 4                4.411043           -0.11071744         -0.0051496337
## 5                3.586310           -0.15464991         -0.0025699598
## 6                5.208763            0.02997812          0.0012870802
## 7                4.659420            0.02563450          0.0004743534
average_fsu<- c((mean(fsu_opponents$pass_epa_per_play)),(mean(fsu_opponents$pass_epa_per_play_def)), (mean(fsu_opponents$rush_epa_per_play_def)), (mean(fsu_opponents$rush_epa_per_play)))

average_mich<- c((mean(mich_opponents$pass_epa_per_play)),(mean(mich_opponents$pass_epa_per_play_def)), (mean(mich_opponents$rush_epa_per_play_def)),(mean(mich_opponents$rush_epa_per_play)))

average_osu<- c((mean(osu_opponents$pass_epa_per_play)),(mean(osu_opponents$pass_epa_per_play_def)), (mean(osu_opponents$rush_epa_per_play_def)), (mean(osu_opponents$rush_epa_per_play)))

average_uga<- c((mean(uga_opponents$pass_epa_per_play)),(mean(uga_opponents$pass_epa_per_play_def)), (mean(uga_opponents$rush_epa_per_play_def)), (mean(uga_opponents$rush_epa_per_play)))

average_wash<- c((mean(wash_opponents$pass_epa_per_play)),(mean(wash_opponents$pass_epa_per_play_def)), (mean(wash_opponents$rush_epa_per_play_def)), (mean(wash_opponents$rush_epa_per_play)))


all_opponents_avg <- data.frame(
  school = c("Florida State", "Michigan", "Washington", "Ohio State", "Georgia"),
  opp_pass_epa_per_play = c(average_fsu[1], average_mich[1], average_wash[1], average_osu[1], average_uga[1]),
  opp_pass_epa_per_play_def = c(average_fsu[2], average_mich[2], average_wash[2], average_osu[2], average_uga[2]),
  opp_rush_epa_per_play_def = c(average_fsu[3], average_mich[3], average_wash[3], average_osu[3], average_uga[3]),
  opp_rush_epa_per_play = c(average_fsu[4], average_mich[4], average_wash[4], average_osu[4], average_uga[4]))
  
all_opponents_avg <- merge(all_opponents_avg, CFP_schools, by = "school")




# Display the resulting data frame
print(all_opponents_avg)
##          school opp_pass_epa_per_play opp_pass_epa_per_play_def
## 1 Florida State            0.10415930                0.09789039
## 2       Georgia            0.16209742                0.14707102
## 3      Michigan            0.02909438                0.09320702
## 4    Ohio State            0.10742402                0.05659843
## 5    Washington            0.15111057                0.13600218
##   opp_rush_epa_per_play_def opp_rush_epa_per_play team_id   color alt_color
## 1               0.030812045            0.06526584      52 #782F40   #ceb888
## 2               0.061461538            0.05458173      61 #CC0000   #000000
## 3              -0.005750138            0.03599749     130 #00274c   #00274c
## 4              -0.001368827            0.04721061     194 #DE3121   #666666
## 5               0.076602279            0.06746383     264 #2B2F64   #e8e3d3
##                                               logos games pass_n pass_yards
## 1  http://a.espncdn.com/i/teamlogos/ncaa/500/52.png    14    450       3386
## 2  http://a.espncdn.com/i/teamlogos/ncaa/500/61.png    14    458       4191
## 3 http://a.espncdn.com/i/teamlogos/ncaa/500/130.png    15    375       3033
## 4 http://a.espncdn.com/i/teamlogos/ncaa/500/194.png    13    406       3435
## 5 http://a.espncdn.com/i/teamlogos/ncaa/500/264.png    15    564       4984
##    pass_epa pass_wpa rush_n rush_yards  rush_epa   rush_wpa pass_yards_per_play
## 1  79.63176 2.003827    430       2352  5.583882 -0.3031046            7.524444
## 2 189.34201 4.208871    480       2763 84.793574  1.4547209            9.150655
## 3 139.01841 3.180742    535       2679 16.143942  1.1494568            8.088000
## 4 141.76881 4.375914    407       2026  2.305381 -0.2555346            8.460591
## 5 205.74318 5.030551    392       1895 41.021508  1.6135143            8.836879
##   pass_epa_per_play pass_wpa_per_play rush_yards_per_play rush_epa_per_play
## 1         0.1769595       0.004452949            5.469767       0.012985773
## 2         0.4134105       0.009189674            5.756250       0.176653280
## 3         0.3707158       0.008481979            5.007477       0.030175593
## 4         0.3491843       0.010778113            4.977887       0.005664326
## 5         0.3647929       0.008919416            4.834184       0.104646704
##   rush_wpa_per_play pass_n_def pass_yards_def pass_epa_def pass_wpa_def
## 1     -0.0007048944        443           2276    -52.17071   -1.4578405
## 2      0.0030306685        438           2312    -46.31946   -0.6245065
## 3      0.0021485174        429           2329    -47.65445   -0.5731249
## 4     -0.0006278491        397           1980    -67.20990   -1.5137899
## 5      0.0041161079        577           3827     39.04008    0.0787014
##   rush_n_def rush_yards_def rush_epa_def rush_wpa_def pass_yards_per_play_def
## 1        457           2495     27.37214    0.3183271                5.137698
## 2        386           1831     23.78378    0.9826433                5.278539
## 3        399           1636    -40.28552   -0.9973048                5.428904
## 4        414           1798    -23.84612   -0.5046498                4.987406
## 5        441           2437     79.85563    1.9417721                6.632582
##   pass_epa_per_play_def pass_wpa_per_play_def rush_yards_per_play_def
## 1           -0.11776685         -0.0032908363                5.459519
## 2           -0.10575218         -0.0014258139                4.743523
## 3           -0.11108263         -0.0013359555                4.100251
## 4           -0.16929446         -0.0038130728                4.342995
## 5            0.06766044          0.0001363976                5.526077
##   rush_epa_per_play_def rush_wpa_per_play_def
## 1            0.05989526          0.0006965582
## 2            0.06161601          0.0025457080
## 3           -0.10096622         -0.0024995108
## 4           -0.05759932         -0.0012189609
## 5            0.18107854          0.0044031113
# Create plot
OPP_Def_EPA_Per_Play_plot <- ggplot(data = all_opponents_avg, # Set dataset
                 aes(x = opp_pass_epa_per_play_def, # Set x-axis variable
                     y = opp_rush_epa_per_play_def)) + # Set y-axis variable
  geom_point() + # Set geom point to create scatter plot
  geom_image(image = CFP_schools$logos, asp = 16/9) + # Add logos
   labs(x = "Opponents Pass EPA DEF Per Play", # Add labels
       y = "Opponents Rush EPA Def Per Play",
       title = "Opponents: Rush v Pass EPA Def Per Play",
       subtitle = "Higher EPA indicates team has played weaker defenses") 

# Turn off dark mode
invert_geom_defaults()


ggsave(OPP_Def_EPA_Per_Play_plot, file = 'OPP_Def_EPA_Per_Play_plot.jpg', width = 10, height = 10, dpi = 600)
# Create plot
OPP_Off_EPA_Per_Play_plot <- ggplot(data = all_opponents_avg, # Set dataset
                 aes(x = opp_pass_epa_per_play, # Set x-axis variable
                     y = opp_rush_epa_per_play)) + # Set y-axis variable
  geom_point() + # Set geom point to create scatter plot
  geom_image(image = CFP_schools$logos, asp = 16/9) + # Add logos
   labs(x = "Opponent Pass EPA Per Play", # Add labels
       y = "Opponent Rush EPA Def Per Play",
       title = "Opponents: Rush v Pass EPA Per Play",
       subtitle = "Higher EPA indicates team has played stronger offenses")

# Turn off dark mode
invert_geom_defaults()


ggsave(OPP_Off_EPA_Per_Play_plot, file = 'OPP_Off_EPA_Per_Play_plot.jpg', width = 10, height = 10, dpi = 600)
# Create plot
Off_EPA_Per_Play_plot <- ggplot(data = CFP_schools, # Set dataset
                 aes(x = rush_epa_per_play, # Set x-axis variable
                     y = pass_epa_per_play)) + # Set y-axis variable
  geom_point() + # Set geom point to create scatter plot
  geom_image(image = CFP_schools$logos, asp = 16/9) + # Add logos
  dark_theme_bw() + # Set dark theme
   labs(x = "Rush EPA Per Play", # Add labels
       y = "Pass EPA Per Play",
       title = "Rush v Pass EPA Per Play",
       subtitle = "Higher EPA indicates stronger offense") 
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
# Turn off dark mode
invert_geom_defaults()

ggsave(Off_EPA_Per_Play_plot, file = 'Off_EPA_Per_Play_plot.jpg', width = 10, height = 10, dpi = 600)
# Create plot
Def_EPA_Per_Play_plot <- ggplot(data = CFP_schools, # Set dataset
                 aes(x = rush_epa_per_play_def, # Set x-axis variable
                     y = pass_epa_per_play_def)) + # Set y-axis variable
  geom_point() + # Set geom point to create scatter plot
  geom_image(image = CFP_schools$logos, asp = 16/9) + # Add logos
  dark_theme_bw() + # Set dark theme
   labs(x = "Rush EPA DEF Per Play", # Add labels
       y = "Pass EPA DEF Per Play",
       title = "Rush v Pass EPA DEF Per Play",
       subtitle = "Lower EPA indicates stronger defense") 
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
# Turn off dark mode
invert_geom_defaults()


ggsave(Def_EPA_Per_Play_plot, file = 'Def_EPA_Per_Play_plot.jpg', width = 10, height = 10, dpi = 600)
number_of_passvsrush_plays_plot <- ggplot(data = CFP_schools, # Set dataset
                 aes(x = rush_n, # Set x-axis variable
                     y = pass_n)) + # Set y-axis variable
  geom_point() + # Set geom point to create scatter plot
  geom_image(image = CFP_schools$logos, asp = 16/9) + # Add logos
  dark_theme_bw() + # Set dark theme
   labs(x = "Number of Rushes", # Add labels
       y = "Number of Passes",
       title = "Rush v Passing Plays",
       subtitle = "CFB 2023") 
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
# Turn off dark mode
invert_geom_defaults()


ggsave(number_of_passvsrush_plays_plot, file = 'number_of_passvsrush_plays_plot.jpg', width = 10, height = 10, dpi = 600)

Create weighted EPA for all teams based on Schedule

weighted_off_def <- all_opponents_avg %>%
  mutate(weighted_passing_off = 10*((1/(0.5+opp_pass_epa_per_play_def))*(pass_epa_per_play+0.5)))%>%
mutate(weighted_rushing_off = 10*((1/(0.5+opp_rush_epa_per_play_def)) * (rush_epa_per_play+0.5)))%>%
  mutate(weighted_passing_def = 10*((1/(0.5+opp_pass_epa_per_play)) * (pass_epa_per_play_def+0.5)))%>%
  mutate(weighted_rushing_def = 10*((1/(0.5+opp_rush_epa_per_play)) * (rush_epa_per_play_def+0.5)))

weighted_off_def
##          school opp_pass_epa_per_play opp_pass_epa_per_play_def
## 1 Florida State            0.10415930                0.09789039
## 2       Georgia            0.16209742                0.14707102
## 3      Michigan            0.02909438                0.09320702
## 4    Ohio State            0.10742402                0.05659843
## 5    Washington            0.15111057                0.13600218
##   opp_rush_epa_per_play_def opp_rush_epa_per_play team_id   color alt_color
## 1               0.030812045            0.06526584      52 #782F40   #ceb888
## 2               0.061461538            0.05458173      61 #CC0000   #000000
## 3              -0.005750138            0.03599749     130 #00274c   #00274c
## 4              -0.001368827            0.04721061     194 #DE3121   #666666
## 5               0.076602279            0.06746383     264 #2B2F64   #e8e3d3
##                                               logos games pass_n pass_yards
## 1  http://a.espncdn.com/i/teamlogos/ncaa/500/52.png    14    450       3386
## 2  http://a.espncdn.com/i/teamlogos/ncaa/500/61.png    14    458       4191
## 3 http://a.espncdn.com/i/teamlogos/ncaa/500/130.png    15    375       3033
## 4 http://a.espncdn.com/i/teamlogos/ncaa/500/194.png    13    406       3435
## 5 http://a.espncdn.com/i/teamlogos/ncaa/500/264.png    15    564       4984
##    pass_epa pass_wpa rush_n rush_yards  rush_epa   rush_wpa pass_yards_per_play
## 1  79.63176 2.003827    430       2352  5.583882 -0.3031046            7.524444
## 2 189.34201 4.208871    480       2763 84.793574  1.4547209            9.150655
## 3 139.01841 3.180742    535       2679 16.143942  1.1494568            8.088000
## 4 141.76881 4.375914    407       2026  2.305381 -0.2555346            8.460591
## 5 205.74318 5.030551    392       1895 41.021508  1.6135143            8.836879
##   pass_epa_per_play pass_wpa_per_play rush_yards_per_play rush_epa_per_play
## 1         0.1769595       0.004452949            5.469767       0.012985773
## 2         0.4134105       0.009189674            5.756250       0.176653280
## 3         0.3707158       0.008481979            5.007477       0.030175593
## 4         0.3491843       0.010778113            4.977887       0.005664326
## 5         0.3647929       0.008919416            4.834184       0.104646704
##   rush_wpa_per_play pass_n_def pass_yards_def pass_epa_def pass_wpa_def
## 1     -0.0007048944        443           2276    -52.17071   -1.4578405
## 2      0.0030306685        438           2312    -46.31946   -0.6245065
## 3      0.0021485174        429           2329    -47.65445   -0.5731249
## 4     -0.0006278491        397           1980    -67.20990   -1.5137899
## 5      0.0041161079        577           3827     39.04008    0.0787014
##   rush_n_def rush_yards_def rush_epa_def rush_wpa_def pass_yards_per_play_def
## 1        457           2495     27.37214    0.3183271                5.137698
## 2        386           1831     23.78378    0.9826433                5.278539
## 3        399           1636    -40.28552   -0.9973048                5.428904
## 4        414           1798    -23.84612   -0.5046498                4.987406
## 5        441           2437     79.85563    1.9417721                6.632582
##   pass_epa_per_play_def pass_wpa_per_play_def rush_yards_per_play_def
## 1           -0.11776685         -0.0032908363                5.459519
## 2           -0.10575218         -0.0014258139                4.743523
## 3           -0.11108263         -0.0013359555                4.100251
## 4           -0.16929446         -0.0038130728                4.342995
## 5            0.06766044          0.0001363976                5.526077
##   rush_epa_per_play_def rush_wpa_per_play_def weighted_passing_off
## 1            0.05989526          0.0006965582             11.32247
## 2            0.06161601          0.0025457080             14.11608
## 3           -0.10096622         -0.0024995108             14.67811
## 4           -0.05759932         -0.0012189609             15.25668
## 5            0.18107854          0.0044031113             13.59733
##   weighted_rushing_off weighted_passing_def weighted_rushing_def
## 1              9.66417             6.326695             9.904990
## 2             12.05164             5.954529            10.126839
## 3             10.72687             7.350624             7.444695
## 4             10.14105             5.444393             8.084651
## 5             10.48637             8.718342            12.002149
weighted_off_plot<- ggplot(data = weighted_off_def, # Set dataset
                 aes(x = weighted_off_def$weighted_rushing_off, # Set x-axis variable
                     y = weighted_off_def$weighted_passing_off)) + # Set y-axis variable
  geom_point() + # Set geom point to create scatter plot
  geom_image(image = CFP_schools$logos, asp = 16/9) + # Add logos
  dark_theme_bw() + # Set dark theme
   labs(x = "Weighted Rushing Offense", # Add labels
       y = "Weighted Passing Offense",
       title = "Weighted Offense",
       subtitle = "CFB 2023") 
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
# Turn off dark mode
invert_geom_defaults()

ggsave(weighted_off_plot, file = 'Weighted_Off_Plot.jpg', width = 10, height = 10, dpi = 600)
## Warning: Use of `weighted_off_def$weighted_rushing_off` is discouraged.
## ℹ Use `weighted_rushing_off` instead.
## Warning: Use of `weighted_off_def$weighted_passing_off` is discouraged.
## ℹ Use `weighted_passing_off` instead.
## Warning: Use of `weighted_off_def$weighted_rushing_off` is discouraged.
## ℹ Use `weighted_rushing_off` instead.
## Warning: Use of `weighted_off_def$weighted_passing_off` is discouraged.
## ℹ Use `weighted_passing_off` instead.
weighted_def_plot <- ggplot(data = weighted_off_def, # Set dataset
                 aes(x = weighted_off_def$weighted_rushing_def, # Set x-axis variable
                     y = weighted_off_def$weighted_passing_def)) + # Set y-axis variable
  geom_point() + # Set geom point to create scatter plot
  geom_image(image = CFP_schools$logos, asp = 16/9) + # Add logos
  dark_theme_bw() + # Set dark theme
   labs(x = "Weighted Rushing Defense", # Add labels
       y = "Weighted Passing Defense",
       title = "Weighted Defense",
       subtitle = "CFB 2023") 
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
# Turn off dark mode
invert_geom_defaults()


ggsave(weighted_def_plot, file = 'Weighted_Def_Plot.jpg', width = 10, height = 10, dpi = 600)
## Warning: Use of `weighted_off_def$weighted_rushing_def` is discouraged.
## ℹ Use `weighted_rushing_def` instead.
## Warning: Use of `weighted_off_def$weighted_passing_def` is discouraged.
## ℹ Use `weighted_passing_def` instead.
## Warning: Use of `weighted_off_def$weighted_rushing_def` is discouraged.
## ℹ Use `weighted_rushing_def` instead.
## Warning: Use of `weighted_off_def$weighted_passing_def` is discouraged.
## ℹ Use `weighted_passing_def` instead.
weighted_pass_defvsoff_plot <- ggplot(data = weighted_off_def, # Set dataset
                 aes(x = weighted_off_def$weighted_passing_def, # Set x-axis variable
                     y = weighted_off_def$weighted_passing_off)) + # Set y-axis variable
  geom_point() + # Set geom point to create scatter plot
  geom_image(image = CFP_schools$logos, asp = 16/9) + # Add logos
  dark_theme_bw() + # Set dark theme
   labs(x = "Weighted Passing Defense", # Add labels
       y = "Weighted Passing Offense",
       title = "Passing Def vs Passing Off",
       subtitle = "CFB 2023") 
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
# Turn off dark mode
invert_geom_defaults()


ggsave(weighted_pass_defvsoff_plot, file = 'weighted_pass_defvsoff.jpg', width = 10, height = 10, dpi = 600)
## Warning: Use of `weighted_off_def$weighted_passing_def` is discouraged.
## ℹ Use `weighted_passing_def` instead.
## Warning: Use of `weighted_off_def$weighted_passing_off` is discouraged.
## ℹ Use `weighted_passing_off` instead.
## Warning: Use of `weighted_off_def$weighted_passing_def` is discouraged.
## ℹ Use `weighted_passing_def` instead.
## Warning: Use of `weighted_off_def$weighted_passing_off` is discouraged.
## ℹ Use `weighted_passing_off` instead.
weighted_rush_defvsoff_plot <- ggplot(data = weighted_off_def, # Set dataset
                 aes(x = weighted_off_def$weighted_rushing_def, # Set x-axis variable
                     y = weighted_off_def$weighted_rushing_off)) + # Set y-axis variable
  geom_point() + # Set geom point to create scatter plot
  geom_image(image = CFP_schools$logos, asp = 16/9) + # Add logos
  dark_theme_bw() + # Set dark theme
   labs(x = "Weighted Rushing Defense", # Add labels
       y = "Weighted Rushing Offense",
       title = "Rushing Def vs Rushing Off",
       subtitle = "CFB 2023") 
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
# Turn off dark mode
invert_geom_defaults()


ggsave(weighted_rush_defvsoff_plot, file = 'weighted_rush_defvsoff.jpg', width = 10, height = 10, dpi = 600)
## Warning: Use of `weighted_off_def$weighted_rushing_def` is discouraged.
## ℹ Use `weighted_rushing_def` instead.
## Warning: Use of `weighted_off_def$weighted_rushing_off` is discouraged.
## ℹ Use `weighted_rushing_off` instead.
## Warning: Use of `weighted_off_def$weighted_rushing_def` is discouraged.
## ℹ Use `weighted_rushing_def` instead.
## Warning: Use of `weighted_off_def$weighted_rushing_off` is discouraged.
## ℹ Use `weighted_rushing_off` instead.
washvsosu <- weighted_off_def %>%
  filter(school %in% c("Washington", "Ohio State"))%>%
mutate(Wash_Passing_Off = 10*(weighted_passing_off[2] * weighted_passing_def[1]))%>%
mutate(Wash_Rushing_Off = 10*(weighted_rushing_off[2] * weighted_rushing_def[1]))%>%
mutate(OSU_Passing_Off = 10*(weighted_passing_off[1] * weighted_passing_def[2]))%>%
mutate(OSU_Rushing_Off = 10*(weighted_rushing_off[1] * weighted_rushing_def[2]))
selected_columns <- c("Wash_Passing_Off", "Wash_Rushing_Off", "OSU_Passing_Off", "OSU_Rushing_Off")

# Melt the dataframe to long format for easier plotting
melted_data_osu <- melt(washvsosu, id.vars = "school", measure.vars = selected_columns)

selected_rows_osu <- melted_data_osu %>%
  slice(c(2, 4, 5, 7))

# Create a grouped bar plot
washvsosu_plot<- ggplot(selected_rows_osu, aes(x = variable, y = value,fill = school)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Comparison of Offense: Washington vs. Ohio State",
       x = "Offense Rating", y = "Values") +
  scale_fill_manual(values = c("firebrick1", "purple")) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

washvsosu_plot

ggsave(washvsosu_plot, file = 'washvsosu_plot.jpg', width = 10, height = 10, dpi = 600)
washvsmich <- weighted_off_def %>%
  filter(school %in% c("Washington", "Michigan"))%>%
mutate(Wash_Passing_Off = 10*(weighted_passing_off[2] * weighted_passing_def[1]))%>%
mutate(Wash_Rushing_Off = 10*(weighted_rushing_off[2] * weighted_rushing_def[1]))%>%
mutate(Mich_Passing_Off = 10*(weighted_passing_off[1] * weighted_passing_def[2]))%>%
mutate(Mich_Rushing_Off = 10*(weighted_rushing_off[1] * weighted_rushing_def[2]))

selected_columns <- c("Wash_Passing_Off", "Wash_Rushing_Off", "Mich_Passing_Off", "Mich_Rushing_Off")

# Melt the dataframe to long format for easier plotting
melted_data_mich <- melt(washvsmich, id.vars = "school", measure.vars = selected_columns)

selected_rows_mich <- melted_data_mich %>%
  slice(c(2, 4, 5, 7))

# Create a grouped bar plot
washvsmich_plot <- ggplot(selected_rows_mich, aes(x = variable, y = value, fill = school)) +
  geom_bar(stat = "identity", position = "dodge") +
  dark_theme_bw() + # Set dark theme
  labs(title = "Comparison of Offense: Washington vs. Michigan",
       x = "Offense Rating", y = "Values") +
  scale_fill_manual(values = c("navy", "purple")) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
## Inverted geom defaults of fill and color/colour.
## To change them back, use invert_geom_defaults().
washvsmich_plot

ggsave(washvsmich_plot, file = 'washvsmich_plot.jpg', width = 10, height = 10, dpi = 600)
washvsfsu <- weighted_off_def %>%
  filter(school %in% c("Washington", "Florida State"))%>%
mutate(Wash_Passing_Off = 10*(weighted_passing_off[2] * weighted_passing_def[1]))%>%
mutate(Wash_Rushing_Off = 10*(weighted_rushing_off[2] *weighted_rushing_def[1]))%>%
mutate(FSU_Passing_Off = 10*(weighted_passing_off[1] * weighted_passing_def[2]))%>%
mutate(FSU_Rushing_Off = 10*(weighted_rushing_off[1] * weighted_rushing_def[2]))

selected_columns <- c("Wash_Passing_Off", "Wash_Rushing_Off", "FSU_Passing_Off", "FSU_Rushing_Off")

# Melt the dataframe to long format for easier plotting
melted_data_fsu <- melt(washvsfsu, id.vars = "school", measure.vars = selected_columns)

selected_rows_fsu <- melted_data_fsu %>%
  slice(c(2, 4, 5, 7))

# Create a grouped bar plot
washvsfsu_plot<- ggplot(selected_rows_fsu, aes(x = variable, y = value, fill = school)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Comparison of Offense: Washington vs. Florida State",
       x = "Offense Rating", y = "Values") +
  scale_fill_manual(values = c("darkred", "purple")) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

washvsfsu_plot

ggsave(washvsfsu_plot, file = 'washvsfsu_plot.jpg', width = 10, height = 10, dpi = 600)
washvsuga <- weighted_off_def %>%
  filter(school %in% c("Washington", "Georgia"))%>%
mutate(Wash_Passing_Off = 10*(weighted_passing_off[2] * weighted_passing_def[1]))%>%
mutate(Wash_Rushing_Off = 10*(weighted_rushing_off[2] * weighted_rushing_def[1]))%>%
mutate(UGA_Passing_Off = 10*(weighted_passing_off[1] * weighted_passing_def[2]))%>%
mutate(UGA_Rushing_Off = 10*(weighted_rushing_off[1] * weighted_rushing_def[2]))

selected_columns <- c("Wash_Passing_Off", "Wash_Rushing_Off", "UGA_Passing_Off", "UGA_Rushing_Off")

# Melt the dataframe to long format for easier plotting
melted_data_uga <- melt(washvsuga, id.vars = "school", measure.vars = selected_columns)

selected_rows_uga <- melted_data_uga %>%
  slice(c(2, 4, 5, 7))

# Create a grouped bar plot
washvsuga_plot <- ggplot(selected_rows_uga, aes(x = variable, y = value, fill = school)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Comparison of Offense: Washington vs. Georgia",
       x = "Offense Rating") +
  scale_fill_manual(values = c("red", "purple")) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

washvsuga_plot

ggsave(washvsuga_plot, file = 'washvsuga_plot.jpg', width = 10, height = 10, dpi = 600)