R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

e1 <- read_xlsx("/Users/na/Desktop/Shri R Projects/ANLY500 Projects/epl/r1.xlsx", sheet = 1)
e1_t4 <- read_xlsx("/Users/na/Desktop/Shri R Projects/ANLY500 Projects/epl/r1.xlsx", sheet = 2)
e1_w <- read_xlsx("/Users/na/Desktop/Shri R Projects/ANLY500 Projects/epl/r1.xlsx", sheet = 3)
e92 <- read_xlsx("/Users/na/Desktop/Shri R Projects/ANLY500 Projects/epl/r1.xlsx", sheet = 4)
e92_t4 <- read_xlsx("/Users/na/Desktop/Shri R Projects/ANLY500 Projects/epl/r1.xlsx", sheet = 5)
e92_w <- read_xlsx("/Users/na/Desktop/Shri R Projects/ANLY500 Projects/epl/r1.xlsx", sheet = 6)

plot(e1_w$Pts)

ggplot(e1_w, aes(x= year, y= Pts)) +
  geom_point() +
  geom_smooth(method = lm, se = FALSE)

#Imp Code Chunk
ggplot(e1_w, aes(x= year, y= Pts, color = Team)) +
  geom_point() +
  geom_smooth(method = lm, se = FALSE) +
theme(axis.text.x=element_text(angle=90, hjust=1))

#ggplot(e1_w, aes(x= year, y= Pts, color = P)) +
 # geom_point() +
#theme(axis.text.x=element_text(angle=90, hjust=1))

#plot(e1_w$t4)
#summary(e1_t4)

factor(e1_t4$Pos)
##   [1] 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1
##  [38] 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2
##  [75] 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
## [112] 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
## [149] 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1
## [186] 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2
## [223] 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3
## [260] 4
## Levels: 1 2 3 4
e1_t4$Pos <- factor(e1_t4$Pos)

#summary(e1_t4)

team_counts <- table(e1_w$Team)
barplot(team_counts, main="Teams", xlab = "Winning Teams", horiz = TRUE)

#Imp code chunk
ggplot(subset (e1, GD>30), aes(x= year, y= Team)) +
  geom_bar(stat = "identity") +
theme(axis.text.x=element_text(angle=90, hjust=1))

xc <- ggplot(subset (e92_w, GD>30), aes(x= reorder(year, -GD), y= Team)) +
  geom_bar(stat = "identity") +
theme(axis.text.x=element_text(angle=90, hjust=1))
fg <- ggplotly(xc)
fg
#ggplot(e1_w) +
 # geom_smooth(mapping = aes(x= year, y= Pts, color= Pos)) +
#theme(axis.text.x=element_text(angle=90, hjust=1))

#Imp code chunk
ggplot(e1_w, aes(x=Team, fill = "Red")) + geom_bar(width = 0.5) + labs(x="Teams", y= "League Wins") + 
  theme_light() + 
  coord_flip() + 
  theme(axis.text.x=element_text(angle=90, hjust=1))

  #labs(title = "All-Cause Mortality Rate for Las Vegas, NV & Boston, MA", subtitle = "(Age-Adjusted; Per 100,000 people)", x = "Year", y = "Mortality Rate", caption = "Data includes 2010-215") +

#barchart(e1_t4$Team)


team_counts <- table(e1_w$Team)

#Additional Attempt
#ggplot(e1_w, aes(x=Team, fill = "Red")) + geom_bar(width = 0.5) + labs(x="Teams", y= "League Wins") + 
 # theme_light() + 
  #coord_flip() + 
  #theme(axis.text.x=element_text(angle=90, hjust=1)) +
#scale_fill_manual(values=c('blue'))


##Attempt 2
#my_e1_w <- ggplot(e1_w, aes(Pts))
#my_e1_w1 <- my_e1_w + geom_histogram(binwidth = 1, color = "blue") + xlab("Sales scores at second measurement time") + ylab("Frequency") + theme_bw()
##my_e1_w1
#cleanup = theme(panel.grid.major = element_blank(),
 #               panel.grid.minor = element_blank(),
  #              panel.background = element_blank(),
   #             axis.line.x = element_line(color = 'black'),
    #            axis.line.y = element_line(color = 'black'),
     #           legend.key = element_rect(fill = 'white'),
      #          text = element_text(size = 15))
#my_e1_w1 + cleanup


#ggplot(e1_w, aes(Pts))  +
    #geom_line(aes(y = Pts), colour = "red") +
  #facet_wrap(~ Team)

#freq_team <- count(e1_t4)
#freq_team
#wteam <- ggplot(e1_t4, aes(x=reorder(Team), color= "blue", fill="cyan")) + geom_bar(stat = "identity")

#imp code chunk
##ggplot(e1_t4, aes(x=Team, color="blue", fill = "Red")) + geom_bar() +
  #labs(x="Teams", y= "Frequency of Top 4 finishes") + theme_classic() + theme_light() + theme(axis.text.x=element_text(angle=90, hjust=1))
library(tidyverse)
ggplot(e1_t4, aes(x= year, y= Pts, color = Pos, linetype = Pos)) +
  geom_point() +
  geom_smooth(method = lm, se = FALSE) +
  theme_classic() +
  geom_line(aes(color = Pos), fill= NA) +
theme(axis.text.x=element_text(angle=90, hjust=1))
## Warning: Ignoring unknown parameters: fill
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

#Imp code chunk
ggplot(e1_t4, aes(x= year, y= Pts, shape = Pos)) +
  geom_point() +
  geom_smooth(method = lm) +
  theme_classic() +
theme(axis.text.x=element_text(angle=90, hjust=1))

Including Plots

You can also embed plots, for example:

ggplot(data = e92_t4, mapping = aes(x=Pos, y= Pts)) +
  geom_boxplot(aes(group=Pos))

ggplot(data = e1_t4, mapping = aes(x=Pos, y= Pts)) +
  geom_boxplot(aes(group=Pos))

ggplot(data = e92_t4, mapping = aes(x=Pos, y= Pts)) +
  geom_boxplot(aes(group=Pos), alpha=0) +
  geom_jitter(alpha=0.8, color = "tomato")

##Imp code chunk
at4 <- ggplot(data = e1_t4, mapping = aes(x=Pos, y= Pts, color=year)) +
  geom_boxplot(aes(group=Pos), alpha=0) +
  geom_jitter(alpha=0.8)
allt4 <- ggplotly(at4)
allt4
## 03/09/2020
##Add Labels
#labs(title = "All-Cause Mortality Rate for Las Vegas, NV & Boston, MA", subtitle = "(Age-Adjusted; Per 100,000 people)", x = "Year", y = "Mortality Rate", caption = "Data includes 2010-215") +
#Imp code chunk
a92t4 <- ggplot(data = e92_t4, mapping = aes(x=Pos, y= Pts, color=year)) +
  geom_boxplot(aes(group=Pos), alpha=0) +
  geom_jitter(alpha=0.8)
all92t4 <- ggplotly(a92t4)
all92t4
agdt4 <- ggplot(data = e1_t4, mapping = aes(x=Pos, y= GD, color=year)) +
  geom_boxplot(aes(group=Pos), alpha=0) +
  geom_jitter(alpha=0.8)
allgdt4 <- ggplotly(agdt4)
allgdt4
#Imp - Factor to 
e92_t4$Pos <- factor(e92_t4$Pos)
e92_t4$year <- factor(e92_t4$year)

#Goal Difference - Decreasing order
agd92t4 <- ggplot(data = e92_t4, mapping = aes(x=Pos, y= GD, color=year)) +
  geom_boxplot(aes(group=Pos), alpha=0) +
  geom_jitter(alpha=0.8)
allgd92t4 <- ggplotly(agd92t4)
allgd92t4
#losses - Increasing order
aloss92t4 <- ggplot(data = e92_t4, mapping = aes(x=Pos, y= L, color=year)) +
  geom_boxplot(aes(group=Pos), alpha=0) +
  geom_jitter(alpha=0.8)
allloss92t4 <- ggplotly(aloss92t4)
allloss92t4
#Wins - Decreasing order
awin92t4 <- ggplot(data = e92_t4, mapping = aes(x=Pos, y= W, color=year)) +
  geom_boxplot(aes(group=Pos), alpha=0) +
  geom_jitter(alpha=0.8)
allwin92t4 <- ggplotly(awin92t4)
allwin92t4
## 03/09/2020
##Add Labels
#labs(title = "All-Cause Mortality Rate for Las Vegas, NV & Boston, MA", subtitle = "(Age-Adjusted; Per 100,000 people)", x = "Year", y = "Mortality Rate", caption = "Data includes 2010-215") +
#####Top 4 - from 92
##Basic graph 92 - top 4
ggplot(data = e92_w, mapping = aes(x=year, y= L)) +
  geom_jitter(alpha=0.8) +
    theme(axis.text.x=element_text(angle=90, hjust=1))

##Imp code chunks- top 4
ggplot(data = e92_t4, mapping = aes(x=year, y= L, color = Pos)) +
  geom_jitter(alpha=0.8) +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#Losses - 92- top 4
ggplot(data = e92_t4, mapping = aes(x=year, y= L, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#Wins - 92- top 4
ggplot(data = e92_t4, mapping = aes(x=year, y= W, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#pts - 92- top 4
ggplot(data = e92_t4, mapping = aes(x=year, y= Pts, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

## 03/09/2020
##Add Labels
#labs(title = "All-Cause Mortality Rate for Las Vegas, NV & Boston, MA", subtitle = "(Age-Adjusted; Per 100,000 people)", x = "Year", y = "Mortality Rate", caption = "Data includes 2010-215") +
#####All data - top 4

e1_t4$Pos <- factor(e1_t4$Pos)
e1_t4$year <- factor(e1_t4$year)

#imp code - top 4
ggplot(data = e1_t4, mapping = aes(x=year, y= L, color = Pos)) +
  geom_jitter(alpha=0.8) +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#Losses - All- top 4
ggplot(data = e1_t4, mapping = aes(x=year, y= L, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#Wins - All- top 4
ggplot(data = e1_t4, mapping = aes(x=year, y= W, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#pts - All- top 4
ggplot(data = e1_t4, mapping = aes(x=year, y= Pts, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

## 03/09/2020
##Add Labels
#labs(title = "All-Cause Mortality Rate for Las Vegas, NV & Boston, MA", subtitle = "(Age-Adjusted; Per 100,000 people)", x = "Year", y = "Mortality Rate", caption = "Data includes 2010-215") +
##All - 92

e1$Pos <- factor(e1$Pos)
e1$year <- factor(e1$year)
e92$Pos <- factor(e92$Pos)
e92$year <- factor(e92$year)
#pts - All
ggplot(data = e92, mapping = aes(x=year, y= Pts, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#Losses - All- top 4
ggplot(data = e92, mapping = aes(x=year, y= L, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#Wins - All- top 4
ggplot(data = e92, mapping = aes(x=year, y= W, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#pts - All- top 4
ggplot(data = e92, mapping = aes(x=year, y= Pts, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

## 03/09/2020
##Add Labels
#labs(title = "All-Cause Mortality Rate for Las Vegas, NV & Boston, MA", subtitle = "(Age-Adjusted; Per 100,000 people)", x = "Year", y = "Mortality Rate", caption = "Data includes 2010-215") +

##All - 92- Winners Only

e92_w$Pos <- factor(e92_w$Pos)
e92_w$year <- factor(e92_w$year)
#pts - All
ggplot(data = e92_w, mapping = aes(x=year, y= Pts, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#Losses - All- top 4
ggplot(data = e92_w, mapping = aes(x=year, y= L, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#Wins - All- top 4
ggplot(data = e92_w, mapping = aes(x=year, y= W, group = Pos, color = Pos)) +
  geom_line() +
    theme(axis.text.x=element_text(angle=90, hjust=1))

#pts - 92 winners
e92allw <- ggplot(data = e92_w, mapping = aes(x=year, y= Pts, fill=Team)) +
  geom_bar(stat = "identity") +
    theme(axis.text.x=element_text(angle=90, hjust=1))
e92wteams <- ggplotly(e92allw)
e92wteams
#pt All Winners
e1allw <- ggplot(data = e1_w, mapping = aes(x=year, y= Pts, fill=Team)) +
  geom_bar(stat = "identity") +
    theme(axis.text.x=element_text(angle=90, hjust=1))
e1wteams <- ggplotly(e1allw)
e1wteams

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.