This is an R Markdown document for Real Madrid. Real Madrid is a football club that was established in 1902. Since then, they have played 3390 matches and still.

Data set for Real Madrid

setwd("C:/Users/User/OneDrive/Fontys/ERP & Business Entelligent/STAT/Assignment/final assignment")
rm <- read.table("RealMadrid.txt",header = TRUE)
rm
##            ï..Competition Season RegionOfPlaying status CalanderYear
## 1   UEFA_Champions_League   1955          Europe      1         1902
## 2   UEFA_Champions_League   1956          Europe      1         1903
## 3   UEFA_Champions_League   1957          Europe      1         1904
## 4   UEFA_Champions_League   1958          Europe      1         1905
## 5   UEFA_Champions_League   1959          Europe      1         1906
## 6   UEFA_Champions_League   1960          Europe      0         1907
## 7   UEFA_Champions_League   1961          Europe      0         1908
## 8   UEFA_Champions_League   1963          Europe      0         1909
## 9   UEFA_Champions_League   1965          Europe      1         1910
## 10  UEFA_Champions_League   1967          Europe      0         1911
## 11  UEFA_Champions_League   1972          Europe      0         1912
## 12  UEFA_Champions_League   1975          Europe      0         1913
## 13  UEFA_Champions_League   1976          Europe      0         1914
## 14  UEFA_Champions_League   1977          Europe      0         1915
## 15  UEFA_Champions_League   1978          Europe      0         1916
## 16  UEFA_Champions_League   1979          Europe      0         1917
## 17  UEFA_Champions_League   1980          Europe      0         1918
## 18  UEFA_Champions_League   1987          Europe      0         1919
## 19  UEFA_Champions_League   1988          Europe      0         1920
## 20  UEFA_Champions_League   1989          Europe      0         1921
## 21  UEFA_Champions_League   1990          Europe      0         1922
## 22  UEFA_Champions_League   1995          Europe      0         1923
## 23  UEFA_Champions_League   1997          Europe      1         1924
## 24  UEFA_Champions_League   1998          Europe      0         1925
## 25  UEFA_Champions_League   1999          Europe      1         1926
## 26  UEFA_Champions_League   2000          Europe      0         1927
## 27  UEFA_Champions_League   2001          Europe      0         1928
## 28  UEFA_Champions_League   2002          Europe      1         1929
## 29  UEFA_Champions_League   2003          Europe      0         1930
## 30  UEFA_Champions_League   2004          Europe      0         1931
## 31  UEFA_Champions_League   2005          Europe      0         1932
## 32  UEFA_Champions_League   2006          Europe      0         1933
## 33  UEFA_Champions_League   2007          Europe      0         1934
## 34  UEFA_Champions_League   2008          Europe      0         1935
## 35  UEFA_Champions_League   2009          Europe      0         1936
## 36  UEFA_Champions_League   2010          Europe      0         1937
## 37  UEFA_Champions_League   2011          Europe      0         1938
## 38  UEFA_Champions_League   2012          Europe      0         1939
## 39  UEFA_Champions_League   2013          Europe      1         1940
## 40  UEFA_Champions_League   2014          Europe      0         1941
## 41  UEFA_Champions_League   2015          Europe      0         1942
## 42               LigaBBVA   1929           Spain      0         1943
## 43               LigaBBVA   1930           Spain      0         1944
## 44               LigaBBVA   1931           Spain      1         1945
## 45               LigaBBVA   1932           Spain      1         1946
## 46               LigaBBVA   1933           Spain      0         1947
## 47               LigaBBVA   1934           Spain      0         1948
## 48               LigaBBVA   1935           Spain      0         1949
## 49               LigaBBVA   1936           Spain      0         1950
## 50               LigaBBVA   1937           Spain      0         1951
## 51               LigaBBVA   1938           Spain      0         1952
## 52               LigaBBVA   1939           Spain      0         1953
## 53               LigaBBVA   1940           Spain      0         1954
## 54               LigaBBVA   1941           Spain      0         1955
## 55               LigaBBVA   1942           Spain      0         1956
## 56               LigaBBVA   1943           Spain      0         1957
## 57               LigaBBVA   1944           Spain      0         1958
## 58               LigaBBVA   1945           Spain      0         1959
## 59               LigaBBVA   1946           Spain      0         1960
## 60               LigaBBVA   1947           Spain      0         1961
## 61               LigaBBVA   1948           Spain      0         1962
## 62               LigaBBVA   1949           Spain      0         1963
## 63               LigaBBVA   1950           Spain      0         1964
## 64               LigaBBVA   1951           Spain      0         1965
## 65               LigaBBVA   1952           Spain      0         1966
## 66               LigaBBVA   1953           Spain      1         1967
## 67               LigaBBVA   1954           Spain      1         1968
## 68               LigaBBVA   1955           Spain      0         1969
## 69               LigaBBVA   1956           Spain      1         1970
## 70               LigaBBVA   1957           Spain      1         1971
## 71               LigaBBVA   1958           Spain      0         1972
## 72               LigaBBVA   1959           Spain      0         1973
## 73               LigaBBVA   1960           Spain      1         1974
## 74               LigaBBVA   1961           Spain      1         1975
## 75               LigaBBVA   1962           Spain      1         1976
## 76               LigaBBVA   1963           Spain      1         1977
## 77               LigaBBVA   1964           Spain      1         1978
## 78               LigaBBVA   1965           Spain      0         1979
## 79               LigaBBVA   1966           Spain      1         1980
## 80               LigaBBVA   1967           Spain      1         1981
## 81               LigaBBVA   1968           Spain      1         1982
## 82               LigaBBVA   1969           Spain      0         1983
## 83               LigaBBVA   1970           Spain      0         1984
## 84               LigaBBVA   1971           Spain      1         1985
## 85               LigaBBVA   1972           Spain      0         1986
## 86               LigaBBVA   1973           Spain      0         1987
## 87               LigaBBVA   1974           Spain      1         1988
## 88               LigaBBVA   1975           Spain      1         1989
## 89               LigaBBVA   1976           Spain      0         1990
## 90               LigaBBVA   1977           Spain      1         1991
## 91               LigaBBVA   1978           Spain      1         1992
## 92               LigaBBVA   1979           Spain      1         1993
## 93               LigaBBVA   1980           Spain      0         1994
## 94               LigaBBVA   1981           Spain      0         1995
## 95               LigaBBVA   1982           Spain      0         1996
## 96               LigaBBVA   1983           Spain      0         1997
## 97               LigaBBVA   1984           Spain      0         1998
## 98               LigaBBVA   1985           Spain      1         1999
## 99               LigaBBVA   1986           Spain      1         2000
## 100              LigaBBVA   1987           Spain      1         2001
## 101              LigaBBVA   1988           Spain      1         2002
## 102              LigaBBVA   1989           Spain      1         2003
## 103              LigaBBVA   1990           Spain      0         2004
## 104              LigaBBVA   1991           Spain      0         2005
## 105              LigaBBVA   1992           Spain      0         2006
## 106              LigaBBVA   1993           Spain      0         2007
## 107              LigaBBVA   1994           Spain      1         2008
## 108              LigaBBVA   1995           Spain      0         2009
## 109              LigaBBVA   1996           Spain      1         2010
## 110              LigaBBVA   1997           Spain      0         2011
## 111              LigaBBVA   1998           Spain      0         2012
## 112              LigaBBVA   1999           Spain      0         2013
## 113              LigaBBVA   2000           Spain      1         2014
## 114              LigaBBVA   2001           Spain      0         2015
## 115              LigaBBVA   2002           Spain      1         2016
## 116              LigaBBVA   2003           Spain      0         2017
## 117              LigaBBVA   2004           Spain      0         2018
## 118              LigaBBVA   2005           Spain      0         2019
## 119              LigaBBVA   2006           Spain      1         2020
## 120              LigaBBVA   2007           Spain      1         2021
## 121              LigaBBVA   2008           Spain      0         2022
## 122              LigaBBVA   2009           Spain      0         2023
## 123              LigaBBVA   2010           Spain      0         2024
## 124              LigaBBVA   2011           Spain      1         2025
## 125              LigaBBVA   2012           Spain      0         2026
## 126              LigaBBVA   2013           Spain      0         2027
## 127              LigaBBVA   2014           Spain      0         2028
## 128              LigaBBVA   2015           Spain      0         2029
##     NumberOfMatchesInIcalanderYear
## 1                                1
## 2                                1
## 3                                1
## 4                                1
## 5                                1
## 6                                1
## 7                                0
## 8                                0
## 9                                0
## 10                               0
## 11                               0
## 12                               0
## 13                               0
## 14                               0
## 15                               0
## 16                               1
## 17                               0
## 18                               0
## 19                               0
## 20                               0
## 21                               0
## 22                               1
## 23                               0
## 24                               0
## 25                               0
## 26                               0
## 27                              19
## 28                              19
## 29                              18
## 30                              18
## 31                              19
## 32                              19
## 33                              22
## 34                              23
## 35                               0
## 36                               0
## 37                               0
## 38                              23
## 39                              22
## 40                              26
## 41                              27
## 42                              26
## 43                              26
## 44                              27
## 45                              27
## 46                              27
## 47                              26
## 48                              26
## 49                              30
## 50                              30
## 51                              30
## 52                              30
## 53                              30
## 54                              37
## 55                              38
## 56                              38
## 57                              38
## 58                              38
## 59                              34
## 60                              41
## 61                              33
## 62                              39
## 63                              36
## 64                              39
## 65                              36
## 66                              38
## 67                              35
## 68                              35
## 69                              40
## 70                              38
## 71                              42
## 72                              37
## 73                              40
## 74                              43
## 75                              38
## 76                              34
## 77                              39
## 78                              43
## 79                              43
## 80                              43
## 81                              46
## 82                              36
## 83                              46
## 84                              46
## 85                              52
## 86                              46
## 87                              49
## 88                              43
## 89                              46
## 90                              49
## 91                              47
## 92                              46
## 93                              44
## 94                              52
## 95                              42
## 96                              51
## 97                              54
## 98                              65
## 99                              57
## 100                             66
## 101                             62
## 102                             59
## 103                             52
## 104                             52
## 105                             50
## 106                             52
## 107                             50
## 108                             48
## 109                             59
## 110                             58
## 111                             61
## 112                             60
## 113                             59
## 114                             53
## 115                              0
## 116                              0
## 117                              0
## 118                              0
## 119                              0
## 120                              0
## 121                              0
## 122                              0
## 123                              0
## 124                              0
## 125                              0
## 126                              0
## 127                              0
## 128                              0

Frequency distributions for Real Madrid dataset

table(rm$Competition)
## < table of extent 0 >
table(rm$Season)
## 
## 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 
##    1    1    1    1    1    1    1    1    1    1    1    2    2    2    2 
## 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 
##    2    2    2    1    2    1    2    1    2    1    1    1    1    2    1 
## 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 
##    1    2    2    2    2    2    2    1    1    1    1    1    1    2    2 
## 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 
##    2    2    1    1    1    1    2    1    2    2    2    2    2    2    2 
## 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 
##    2    2    2    2    2    2    2    2    2    2    2    2
table(rm$RegionOfPlaying)
## 
## Europe  Spain 
##     41     87
table(rm$status)
## 
##  0  1 
## 86 42
table(rm$CalanderYear)
## 
## 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 2022 2023 2024 2025 2026 2027 2028 2029 
##    1    1    1    1    1    1    1    1
table(rm$NumberOfMatCalanderYearchesInIcalanderYear)
## < table of extent 0 >
summary(rm)
##                ï..Competition     Season     RegionOfPlaying
##  LigaBBVA             :87     Min.   :1929   Europe:41      
##  UEFA_Champions_League:41     1st Qu.:1958   Spain :87      
##                               Median :1978                  
##                               Mean   :1977                  
##                               3rd Qu.:1999                  
##                               Max.   :2015                  
##      status        CalanderYear  NumberOfMatchesInIcalanderYear
##  Min.   :0.0000   Min.   :1902   Min.   : 0.00                 
##  1st Qu.:0.0000   1st Qu.:1934   1st Qu.: 0.00                 
##  Median :0.0000   Median :1966   Median :30.00                 
##  Mean   :0.3281   Mean   :1966   Mean   :26.49                 
##  3rd Qu.:1.0000   3rd Qu.:1997   3rd Qu.:43.00                 
##  Max.   :1.0000   Max.   :2029   Max.   :66.00

Central tendencies of the matches per season

mean(rm$NumberOfMatchesInIcalanderYear)
## [1] 26.49219
mode(rm$NumberOfMatchesInIcalanderYear)
## [1] "numeric"
median(rm$NumberOfMatchesInIcalanderYear)
## [1] 30

Data dispersity of matches per season

sum(rm$NumberOfMatchesInIcalanderYear)
## [1] 3391
range(rm$NumberOfMatchesInIcalanderYear)
## [1]  0 66
max(rm$NumberOfMatchesInIcalanderYear)
## [1] 66
min(rm$NumberOfMatchesInIcalanderYear)
## [1] 0
if (!require("ggplot2")) {
install.packages("ggplot2")
library(ggplot2)
}
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.2.5

Here I am displaying the number of matches per year in ggplot in different formats

‘d’ is a variable that holds the ggplot function.
ggplot() displays the retrieved data from the dataset, x=calanderYear, y=NumberOfMatches. labs() is the function used to label the x,y.
The second line: Is a representation of a geom_point() format of ggplot() which is used to create scatterplots in points . The scatterplots shows the relationship between x,y.After that, a theme() function is used twice to set the color and the font size of the main title and x,y titles.
d <- ggplot(rm, aes(x=CalanderYear,y=NumberOfMatchesInIcalanderYear))+labs(x="Year",y="Number of matches") +  ggtitle("Number of matches per year")  
d + geom_point(aes(colour = NumberOfMatchesInIcalanderYear))  + 
  theme(plot.title = element_text( color="blue", face="bold", size=28, hjust=0)) +
  theme(axis.title = element_text( color="blue", face="bold", size=18)) 

d + geom_line(colour = "deepskyblue2", size= 2)+  
  theme(plot.title = element_text( color="blue", face="bold", size=28, hjust=0)) +
  theme(axis.title = element_text( color="blue", face="bold", size=18)) 

I used subset function to make new data from the existing dataset to get
rm <- read.table("RealMadrid.txt",header = TRUE)
nrWinningTrophies_LigaBBVA <- subset(rm ,rm$status == 1& rm$ï..Competition== "LigaBBVA")
sum(nrWinningTrophies_LigaBBVA$status)
## [1] 32
liga <- ggplot(nrWinningTrophies_LigaBBVA, aes(x=Season ,y= status)) +  ggtitle("LigaBBVA winning seasons")
liga  + geom_point(color="brown")

rm <- read.table("RealMadrid.txt",header = TRUE)
nrWinningTrophies_UEFA_Champions_League <- subset(rm ,rm$status == 1& rm$ï..Competition== "UEFA_Champions_League")
sum(nrWinningTrophies_UEFA_Champions_League$status)
## [1] 10
Champion <- ggplot(nrWinningTrophies_UEFA_Champions_League, aes(x=Season ,y= status)) +  ggtitle("UEFA_Champions_League winning seasons")
Champion + geom_point(color="green", size = 2)    + geom_text(aes(label=Season),hjust=0, vjust=0, check_overlap = TRUE, angle = 90, size = 2) 

Relationship between ‘calander year’ and ‘matches per calander year’

matches_per_year <- ggplot(rm,aes(x= CalanderYear,y=NumberOfMatchesInIcalanderYear)) + ggtitle("Number of matches per year") + labs(x="Year",y="Number of matches")
matches_per_year + geom_point(color="purple", size = 2.5) +geom_line(color="gray")