setwd("~/Graphing")
library(tidyverse)
pos <- read.csv("FinalProject_MLB_Positions.csv")
str(df)
mlb<- read.csv("FinalProject_MLB.csv")
colteam<-c("#56b4E9","#FF0000","#0072B2","#000000","#FFCC00")
colpos<-c("#D55E00","#0072B2","#009E73")
ggplot(data=mlb,mapping=aes(x=Year,y=RBI,color=Team,fill=Team))+
geom_line(aes(color=Team),size=1)+
geom_point(size=2,pch=22)+
scale_x_continuous(breaks=seq(2010,2020,2),
expan=expansion(mult=c(0.04,0.05)))+
scale_y_continuous(name="Number of RBI's",breaks=seq(575,800,25))+
scale_color_manual(values=colteam)+
scale_fill_manual(values=colteam)+
facet_wrap(vars(Team),scales="free_y")+
theme_bw()+
theme(panel.grid.minor=element_blank(),legend.position="none",
axis.title.x=element_text(margin=margin(t=6,b=0,unit="mm"),face="bold"),
axis.title.y=element_text(margin=margin(l=0,r=6,unit="mm"),face="bold"),
plot.title=element_text(face="bold",size=14),
plot.background=element_rect(fill="linen"))+
labs(title="Number of RBI's Recorded for the MLB's NLC Division",
subtitle="For the 2010-2019 seasons" )
ggplot(data=pos,mapping=aes(x=position,y=bat.avg,color=position,fill=position))+
geom_boxplot(alpha=0.5,size=.75)+
scale_x_discrete(name="Position Type")+
scale_y_continuous(name="Batting Average",breaks=seq(0.20,0.35,0.05),
expand=expansion(mult=c(0.1,0.05)))+
scale_color_manual(values=colpos)+
scale_fill_manual(values=colpos)+
theme_bw()+
theme(panel.grid.minor.y=element_blank(),panel.grid.major=element_blank(),legend.position="none",
axis.title.x=element_text(size=13,face="bold",margin=margin(t=6,b=0,unit="mm")),
axis.title.y=element_text(size=13,face="bold",margin=margin(l=0,r=7,unit="mm")),
axis.text=element_text(size=12),
plot.background=element_rect(fill="linen"),
plot.title=element_text(face="bold",size=16))+
labs(title="2019 Major League Baseball Batting Averages",
subtitle="Based on fielding position",
caption="Corner Position = 1B, 3B, C\n Middle Position = 2B, SS\nOutfield = LF, CF, RF\n(Pitchers are excluded from data)")