library(ggplot2)
library(ggdist)
library(tidyquant)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## ── Attaching core tidyquant packages ─────────────────────── tidyquant 1.0.12 ──
## ✔ PerformanceAnalytics 2.0.8 ✔ TTR 0.24.4
## ✔ quantmod 0.4.28 ✔ xts 0.14.2
## ── Conflicts ────────────────────────────────────────── tidyquant_conflicts() ──
## ✖ zoo::as.Date() masks base::as.Date()
## ✖ zoo::as.Date.numeric() masks base::as.Date.numeric()
## ✖ PerformanceAnalytics::legend() masks graphics::legend()
## ✖ quantmod::summary() masks base::summary()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Crear el conjunto de datos
nba_data <- data.frame(
Jugador = c("Luka Doncic", "S. Gilgeous-Alexander", "Jalen Brunson", "Stephen Curry",
"Devin Booker", "Tyrese Haliburton", "Damian Lillard", "De'Aaron Fox",
"Ja Morant", "Trae Young", "Joel Embiid", "Nikola Jokic",
"Anthony Davis", "Victor Wembanyama", "Domantas Sabonis", "Bam Adebayo",
"Alperen Sengun", "Chet Holmgren", "Rudy Gobert", "Jarrett Allen"),
Posicion = c(rep("Base (G)", 10), rep("Pivot (C)", 10)),
PPG = c(33.9, 30.1, 28.7, 26.4, 27.1, 20.1, 24.3, 26.6, 25.1, 25.7,
34.7, 26.4, 24.7, 21.4, 19.4, 19.3, 21.1, 16.5, 14.0, 16.5)
)
ggplot(nba_data, aes(x = Posicion, y = PPG, fill = Posicion)) +
# 1. La Nube
stat_halfeye(
adjust = 0.5,
justification = -0.2,
.width = 0,
point_colour = NA
) +
# 2. El Rayo (Boxplot)
geom_boxplot(
width = 0.12,
outlier.shape = NA, # EvitO duplicar los puntos de la lluvia
alpha = 0.5
) +
# 3. La Lluvia (Puntos con 'jitter' para evitar solapamiento)
stat_dots(
side = "left", # Puntos a la izquierda
justification = 1.1, # Alineación
binwidth = 0.4 # Tamaño de los puntos
) +
# Estética y Etiquetas
scale_fill_tq() +
theme_tq() +
labs(
title = "Distribución de Anotación NBA: Bases vs PÃvots",
subtitle = "Temporada Regular 2023-2024 (PPG)",
x = "Posición en el campo",
y = "Puntos por Partido (PPG)",
caption = "Datos: NBA Stats | Visualización: Raincloud Plot"
) +
coord_flip()
