Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dataframe <- read.csv('rushing.csv', header = TRUE,sep = ",")
#filter for 16 game seasons and running backs
sixteenGamesdf <- dataframe %.% filter(Pos == 'TB' | Pos =='rb' | Pos == 'RB' , Year >= 1978)
sixteenGamesdf$Tm[sixteenGamesdf$Tm=="RAM"]<-"STL"
sixteenGamesdf$Tm[sixteenGamesdf$Tm=="PHO"]<-"ARI"
sixteenGamesdf$Tm[sixteenGamesdf$Tm=="RAI"]<-"OAK"
ggplot(data=sixteenGamesdf, aes(x=Age,y=Yds))+
scale_x_continuous() +
scale_y_continuous()+
labs(title="Running Back Age vs Rushing Yards",y="Yards", x="Age")+
geom_point(aes(color = Tm), size = 3.0,
position = position_jitter(width=.3, height=0))
sixteenGamesdf$Tm[sixteenGamesdf$Tm=="RAM"]<-"STL"
sixteenGamesdf$Tm[sixteenGamesdf$Tm=="PHO"]<-"ARI"
sixteenGamesdf$Tm[sixteenGamesdf$Tm=="RAI"]<-"OAK"
nflPalette <- c("#97233F", "#A71930", "#241773", "#C60C30",
"#0085CA","#C83803","#FB4F14", "Brown",
"#002244", "#FB4F14","#005A8B","#203731",
"#A71930","#002C5F","#006778","#E31837",
"#008E97","#4F2683","#C60C30","#9F8958",
"#0B2265","#203731","#A5ACAF","#004953",
"#FFB612","#0073CF","#69BE28","#B3995D",
"#B3995D","#D50A0A","#002244","#773141")
ggplot(sixteenGamesdf, aes(x=Age,y=Yds))+
scale_x_continuous() +
scale_y_continuous()+
scale_fill_manual(values=nflPalette)+
labs(title="Running Back Age vs Rushing Yards",y="Yards", x="Age")+
geom_point(aes(fill = Tm),colour="#e5e5e5", shape=21, size = 3.5,
position = position_jitter(width=.3, height=0))+
geom_smooth(method='lm',formula=y~x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.