library (tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.1 ✔ purrr 1.0.1
## ✔ tibble 3.1.6 ✔ dplyr 1.1.0
## ✔ tidyr 1.3.0 ✔ stringr 1.5.0
## ✔ readr 2.1.4 ✔ forcats 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(dplyr)
library(ggplot2)
library(readxl)
#Lenyendo archivos de Excel teams, stadiums, players, managers, matches, goals y se convierten en dataframe teams, stadiums, players, managers, matches, goals
teams <- read_excel("UEFA Data SP.xlsx", sheet = "teams")
stadiums <- read_excel("UEFA Data SP.xlsx", sheet = "stadiums")
players <- read_excel("UEFA Data SP.xlsx", sheet = "players")
managers <- read_excel("UEFA Data SP.xlsx", sheet = "managers")
matches <- read_excel("UEFA Data SP.xlsx", sheet = "matches")
goals <- read_excel("UEFA Data SP.xlsx", sheet = "goals")
View(teams)
## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)),
## stdout = TRUE): running command ''/usr/bin/otool' -L
## '/Library/Frameworks/R.framework/Resources/modules/R_de.so'' had status 1
View(stadiums)
## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)),
## stdout = TRUE): running command ''/usr/bin/otool' -L
## '/Library/Frameworks/R.framework/Resources/modules/R_de.so'' had status 1
view(players)
view(matches)
view(goals)
#1.-¿Cuál es la capacidad promedio, mayor y menor de los estadios europeos?
promediosestadios <- stadiums%>%
summary(CAPACITY)
promediosestadios
## NAME CITY COUNTRY CAPACITY
## Length:86 Length:86 Length:86 Min. : 4735
## Class :character Class :character Class :character 1st Qu.:29834
## Mode :character Mode :character Mode :character Median :43758
## Mean :45295
## 3rd Qu.:60800
## Max. :99354
#al aplicar la función summary, es que podemos encontrar el promedio, mayor y menor de los estadios europeos, siendo estos 4,735 el minimo, 45,295 el promedio y 99,354 el maximo.
2.-¿Cuál es el top ten de los estadios europeos con capacidad superior al promedio (obtenido en la pregunta anterior) ?.Despliega Nombre, País y capacidad
estadioscapacidad <- stadiums%>%
select(NAME, CAPACITY, COUNTRY)%>%
arrange(desc(CAPACITY))%>%
head(10)
estadioscapacidad
## # A tibble: 10 × 3
## NAME CAPACITY COUNTRY
## <chr> <dbl> <chr>
## 1 Spotify Camp Nou 99354 Spain
## 2 Wembley Stadium 90000 England
## 3 Signal Iduna Park 81365 Germany
## 4 Stade de France 81338 France
## 5 Santiago Bernabéu 81044 Spain
## 6 Luzhniki 80840 Russia
## 7 Giuseppe Meazza 75923 Italy
## 8 Allianz Arena 75024 Germany
## 9 Millennium 74500 Wales
## 10 Old Trafford 74140 England
#En este segundo ejercicio, se pueden ver los 10 estadios con mayor capacidad dentro de la base de datos. Al volver a el primer ejercicio, donde el promedio era de 45,295, comprobamos que los 10 estadios que estan aquí, estan por encima del promedio. Esto se pudo hacer con la función select (para mostrar solo nombre y capacidad), arrange(desc(para mostrar los mas altos)) y finalmente head, para solo mostrar los primeros 10.
3.-¿Cuáles son los 10 equipos con más jugadores de la liga desde 2016 a 2022 y cuántos jugadores tiene cada equipo?. Elimina a los equipos con NA’s.
equiposjugadores <- players %>%
select(PLAYER_ID, TEAM)%>%
group_by(TEAM)%>%
filter(!is.na(TEAM))%>%
summarise(num_jugadores=n())%>%
arrange(desc(num_jugadores))%>%
head(10)
equiposjugadores
## # A tibble: 10 × 2
## TEAM num_jugadores
## <chr> <int>
## 1 Borussia Dortmund 48
## 2 Liverpool FC 46
## 3 Manchester United 44
## 4 Olympiakos Piraeus 42
## 5 Slavia Praha 39
## 6 Bayern München 38
## 7 Dinamo Kiev 38
## 8 Ferencvárosi TC 37
## 9 APOEL Nikosia 35
## 10 FK Krasnodar 35
#En este tercer ejercicio, mediante el uso de las herramientas select, group_by, filter, summarise, arrange y head, se logro obtener los 10 equipos que mas jugadores han tenido en la competición. Así como lograr acomodarlos de manera descendente. Obtuvimos que el equipo Borussia Dortmund, de alemania, es el equipo que mas jugadores utilizo, con 48.
4.-¿Cuáles son los 10 estadios que recibieron mayor audiencia durante las ligas?. Despliega el estadio, la audiencia, equipo local y visitante.
asistenciaestadios <- matches%>%
select(STADIUM, ATTENDANCE, HOME_TEAM, AWAY_TEAM)%>%
arrange(desc(ATTENDANCE))%>%
head(10)
asistenciaestadios
## # A tibble: 10 × 4
## STADIUM ATTENDANCE HOME_TEAM AWAY_TEAM
## <chr> <dbl> <chr> <chr>
## 1 Spotify Camp Nou 98299 FC Barcelona Liverpool FC
## 2 Spotify Camp Nou 97183 FC Barcelona Chelsea FC
## 3 Spotify Camp Nou 96708 FC Barcelona Manchester United
## 4 Spotify Camp Nou 96290 FC Barcelona Manchester City
## 5 Spotify Camp Nou 96290 FC Barcelona Paris Saint-Germain
## 6 Spotify Camp Nou 96290 FC Barcelona Juventus
## 7 Spotify Camp Nou 92346 FC Barcelona Olympique Lyon
## 8 Spotify Camp Nou 90106 FC Barcelona AS Roma
## 9 Spotify Camp Nou 90071 FC Barcelona Borussia Dortmund
## 10 Spotify Camp Nou 86290 FC Barcelona Inter
#En este cuarto inciso, obvtuve que los 10 partidos con mayor asistencia le pertenecen al estadio Spotify Camp nou, esto tiene mucho sentido debido a que en el ejercicio 2 de esta evidencia, se pudo ver que este es el estadio con mayor capacidad. Esto se pudo hacer mediante las funciones select, arrange, y head.
#VISUALIZACIÓN 1 - DISPERSIÓN.
g1 <- matches%>%
left_join(stadiums, by= c("STADIUM" = "NAME"))
## Warning in left_join(., stadiums, by = c(STADIUM = "NAME")): Each row in `x` is expected to match at most 1 row in `y`.
## ℹ Row 4 of `x` matches multiple rows.
## ℹ If multiple matches are expected, set `multiple = "all"` to silence this
## warning.
g1
## # A tibble: 767 × 13
## MATCH_ID SEASON DATE_TIME HOME_TEAM AWAY_TEAM STADIUM HOME_TEAM_SCORE
## <chr> <chr> <chr> <chr> <chr> <chr> <dbl>
## 1 mt1 2021-2022 15-SEP-21 08.… Manchest… RB Leipz… Etihad… 6
## 2 mt2 2021-2022 15-SEP-21 08.… Club Bru… Paris Sa… Jan Br… 1
## 3 mt3 2021-2022 28-SEP-21 08.… Paris Sa… Manchest… Parc d… 2
## 4 mt4 2021-2022 28-SEP-21 08.… RB Leipz… Club Bru… Red Bu… 1
## 5 mt4 2021-2022 28-SEP-21 08.… RB Leipz… Club Bru… Red Bu… 1
## 6 mt5 2021-2022 19-OCT-21 05.… Club Bru… Manchest… Jan Br… 1
## 7 mt6 2021-2022 19-OCT-21 08.… Paris Sa… RB Leipz… Parc d… 3
## 8 mt7 2021-2022 03-NOV-21 08.… RB Leipz… Paris Sa… Red Bu… 2
## 9 mt7 2021-2022 03-NOV-21 08.… RB Leipz… Paris Sa… Red Bu… 2
## 10 mt8 2021-2022 03-NOV-21 08.… Manchest… Club Bru… Etihad… 4
## # … with 757 more rows, and 6 more variables: AWAY_TEAM_SCORE <dbl>,
## # PENALTY_SHOOT_OUT <dbl>, ATTENDANCE <dbl>, CITY <chr>, COUNTRY <chr>,
## # CAPACITY <dbl>
ggplot(data = g1,
mapping = aes(x = CAPACITY, y = ATTENDANCE)) +
geom_point(alpha =0.2)+
labs(title= "Correlación entre capacidad de los estadios y asistencia a los partidos. ",
subtitle = "Gráfica de dispersión",
x= "CAPACIDAD",
y= "ASISTENCIA")
#EN ESTA PRIMERA VISUALIZACIÓN, PODEMOS VER UNA GRAFICA DE DISPERSIÓN
DONDE SE VEN LA CAPACIDAD Y ASISTENCIA DE LOS ESTADIOS, COMO PODEMOS
VER, EN LA MAYORIA DE LOS CASOS, LA CAPACIDAD DEL ESTADIO ES ALCANZADA
POR LA ASISTENCIA QUE TUVO (SIGNIFICANDO QUE SE LLENO), ME GUSTARIA
RESALTAR QUE SE PUEDEN LLEGAR A VER ASISTENCIAS DE 0, QUE PUEDEN VENIR
DE LA PANDEMIA QUE SE TUVO.
#EL HACER UNA GRAFICA DE LINEAS, NO SE PUDO REALIZAR, DEBIDO QUE A DIFERENCIA DE LA BASE DE DATOS NYCFLIGHTS, EN ESTA NO SE TIENEN FECHAS, POR LO CUAL NO TENEMOS VARIABLES DE NATURALEZA SECUENCIAL.
#VISUALIZACIÓN 2 BARRAS
partidosanfield <- matches %>%
filter(STADIUM =="Anfield")
partidosanfield
## # A tibble: 26 × 10
## MATCH_ID SEASON DATE_TIME HOME_TEAM AWAY_TEAM STADIUM HOME_TEAM_SCORE
## <chr> <chr> <chr> <chr> <chr> <chr> <dbl>
## 1 mt14 2021-2022 15-SEP-21 08.… Liverpoo… AC Milan Anfield 3
## 2 mt20 2021-2022 03-NOV-21 08.… Liverpoo… Atlético… Anfield 2
## 3 mt21 2021-2022 24-NOV-21 08.… Liverpoo… FC Porto Anfield 2
## 4 mt106 2021-2022 08-MAR-22 08.… Liverpoo… Inter Anfield 0
## 5 mt120 2021-2022 13-APR-22 08.… Liverpoo… SL Benfi… Anfield 3
## 6 mt122 2021-2022 27-APR-22 08.… Liverpoo… Villarre… Anfield 2
## 7 mt165 2020-2021 27-OCT-20 08.… Liverpoo… FC Midtj… Anfield 2
## 8 mt169 2020-2021 25-NOV-20 08.… Liverpoo… Atalanta Anfield 0
## 9 mt171 2020-2021 01-DEC-20 08.… Liverpoo… AFC Ajax Anfield 1
## 10 mt245 2020-2021 14-APR-21 08.… Liverpoo… Real Mad… Anfield 0
## # … with 16 more rows, and 3 more variables: AWAY_TEAM_SCORE <dbl>,
## # PENALTY_SHOOT_OUT <dbl>, ATTENDANCE <dbl>
ggplot(data = partidosanfield, mapping = aes(x = HOME_TEAM_SCORE)) +
geom_histogram()+ geom_histogram(color = "green")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
labs(title= "GOLES LIVERPOOL LOCAL",
subtitle = "Histograma",
x="Goles liverpool",
y="frecuencia.")
## $x
## [1] "Goles liverpool"
##
## $y
## [1] "frecuencia."
##
## $title
## [1] "GOLES LIVERPOOL LOCAL"
##
## $subtitle
## [1] "Histograma"
##
## attr(,"class")
## [1] "labels"
#EN ESTA SEGUNDA VISUALIZACIÓN PODEMOS VER LOS GOLS QUE ANOTO EL EQUIPO LIVERPOOL EN SUS PARTIDOS DE LOCAL, A TRAVES DE TODAS LAS TEMPORADAS. ESTO NOS PERMITE VER EL RANGO DE GOLES QUE ANOTA, Y CUALES SON LA CANTIDAD DE GOLES QUE MAS ANOTA CUANDO ES LOCAL (SIENDO ESTE VALOR 2)
#VISUALIZACIÓN 3 HISTOGRAMAS.
g3 <- players
ggplot(data = g3, mapping = aes(x = JERSEY_NUMBER)) + geom_histogram(color = "purple")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 316 rows containing non-finite values (`stat_bin()`).
#EN ESTA TERCERA VISUALIZACIÓN, PODEMOS VER LA CANTIDAD DE VECES QUE SE
REPITE EL NUMERO EN DORSAL DE CADA JUGADOR, AL ANALIZARLA, NOS DAMOS
CUENTA QUE LOS NUMERO QUE MAS SE REPITEN VAN DESDE EL 1-30, Y DESPUES SE
VE UNA REDUCCIÓN CONSIDERABLE, DANDONOS A ENTENDER QUE LOS NUMEROS POR
ENCIMA DE 40, NO SON DE MUCHO AGRADO PARA LOS JUGADORES. #VISUALIZACIÓN
4 - FACETS
estadiositalia <- matches %>%
left_join(stadiums, by= c("STADIUM" = "NAME"))%>%
filter(COUNTRY == "Italy")
## Warning in left_join(., stadiums, by = c(STADIUM = "NAME")): Each row in `x` is expected to match at most 1 row in `y`.
## ℹ Row 4 of `x` matches multiple rows.
## ℹ If multiple matches are expected, set `multiple = "all"` to silence this
## warning.
ggplot(data = estadiositalia, mapping = aes(x = AWAY_TEAM_SCORE)) +
geom_histogram(binwidth = 1, color = "white") +
facet_wrap(~ STADIUM, nrow = 2)+
labs(title="GOLES DE VISITANTE EN ITALIA",
subtitle = "Histogramas",
x="GOLES VISITANTE",
y="Frecuencia")
#EN ESTA CUARTA VISUALIZACIÓN, PODEMOS VER FACETS, DONDE VEMOS LOS
DIFERENTES ESTADIOS EN ITALIA, ASÍ COMO LA CANTIDAD DE GOLES QUE PUDO
METER EL EQUIPO VISITANTE EN CADA UNO DE ELLOS.
#VISUALIZACIÓN 4 - DIAGRAMA DE CAJAS.
estadioscapacidad
## # A tibble: 10 × 3
## NAME CAPACITY COUNTRY
## <chr> <dbl> <chr>
## 1 Spotify Camp Nou 99354 Spain
## 2 Wembley Stadium 90000 England
## 3 Signal Iduna Park 81365 Germany
## 4 Stade de France 81338 France
## 5 Santiago Bernabéu 81044 Spain
## 6 Luzhniki 80840 Russia
## 7 Giuseppe Meazza 75923 Italy
## 8 Allianz Arena 75024 Germany
## 9 Millennium 74500 Wales
## 10 Old Trafford 74140 England
ej4 <- estadioscapacidad%>%
group_by(COUNTRY)
ej4
## # A tibble: 10 × 3
## # Groups: COUNTRY [7]
## NAME CAPACITY COUNTRY
## <chr> <dbl> <chr>
## 1 Spotify Camp Nou 99354 Spain
## 2 Wembley Stadium 90000 England
## 3 Signal Iduna Park 81365 Germany
## 4 Stade de France 81338 France
## 5 Santiago Bernabéu 81044 Spain
## 6 Luzhniki 80840 Russia
## 7 Giuseppe Meazza 75923 Italy
## 8 Allianz Arena 75024 Germany
## 9 Millennium 74500 Wales
## 10 Old Trafford 74140 England
ggplot(data = ej4, mapping = aes(x = factor(COUNTRY), y = CAPACITY)) + geom_boxplot()
#EN ESTA QUINTA VISUALIZACIÓN PODEMOS VER UNOS DIAGRAMAS DE CAJA, DONDE
VOLVIENDO AL SEGUNDO EJERCICIO REALIZADO, Y AGRUPANDO POR PAIS, EN LOS
ESTADIOS CON PAISES QUE SE REPITEN DEL TOP 10 CON MAS CAPACIDAD, PODEMOS
VER UN DIAGRAMA DE CAJA.
Parte III Compromiso ético y ciudadano • Describe el valor de la integridad. • Agrega una reflexión personal de cómo puedes actuar con respeto y honestidad en los negocios y en el uso de datos cuando realices análisis de datos y estés en contacto con los datos de una empresa. • Agrega al menos tres referencias bibliográficas y cítalas en el punto anterior. Referencia adicional para esta sub sección: http://codigoeticaeintegridad.com/ #EL VALOR DE LA INTEGRIDAD. #La integridad es un valor fundamental en la sociedad, esta se basa en la honestidad, y la ética en todas las acciones y decisiones que tomamos en día a día. Implica actuar con responsabilidad y de acuerdo con lo que se considera correcto y justo, incluso en situaciones difíciles, la integridad es un pilar esencial para construir relaciones de confianza, tanto en el ámbito personal como profesional. Por otra parte, es un requisito indispensable para el éxito y el respeto en cualquier área de la vida. La falta de integridad puede generar consecuencias negativas tanto para uno mismo como para quienes lo rodean. #REFLEXIÓN PERSONAL. #Como reflexión personal, en el uso de datos y en los negocios, el actuar con respeto y honestidad significa el siempre ser honesto con los resultados que se tienen, o en otras palabras, jamas manipular una base de datos de una manera que se enseñen o muestren datos que verdaderamente “no” se encuentran ahí. Como analistas de datos, es nuestra responsabilidad ser honestos en todo momento, pues “manipular de mala manera” una base de datos, podria significar la desinformación total de una empresa, y malas tomas de decisiones. #REFERENCIAS “The Importance of Integrity in Business” por Entrepreneur de https://www.entrepreneur.com/article/293715 “Why Integrity is the Most Important Value to Have” por Forbes de https://www.forbes.com/sites/kathycaprino/2014/07/29/why-integrity-is-the-most-important-value-to-have/?sh=6c33c51269a5 “The Value of Integrity in Life and Business” por The Balance Small Business de https://www.thebalancesmb.com/the-value-of-integrity-in-life-and-business-4154177