Packages

Data

data1 <- read.csv("LOL_STATS.csv")
data2 <- read.csv("lol_champ_wr.csv")
View(data2)
View(data1)

Personal Visualizations

Champion Performance: Bar Chart

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
filtered_data <- data2 %>%
  filter(GamesPlayed >= 10)

ggplot(filtered_data, aes(x = Winrate, y = reorder(Champion, -Winrate))) +
  geom_bar(stat = "identity", position = "dodge", fill = "lightblue", color = "black", width = 0.7) +
  labs(title = "Win Rates of Different Champion (Games Played >= 10)",
       x = "Win Rate (%)",
       y = "Champion") +
  theme_minimal() +
  theme(legend.position = "none",  
        plot.title = element_text(hjust = 0.5),  
        axis.text.y = element_text(hjust = 0)) +  
  geom_text(aes(label = sprintf("%.1f%%", Winrate)), 
            position = position_dodge(width = 0.7),
            hjust = -0.2) +  
  geom_point(data = filtered_data[which.min(filtered_data$Winrate), , drop = FALSE], 
             aes(x = Winrate, y = reorder(Champion, -Winrate)), 
             color = "red", size = 3) +  
  geom_point(data = filtered_data[which.max(filtered_data$Winrate), , drop = FALSE], 
             aes(x = Winrate, y = reorder(Champion, -Winrate)), 
             color = "green", size = 3) +  
  theme(legend.title = element_blank()) 
## Warning: Removed 1 rows containing missing values (`geom_bar()`).
## Warning: Removed 1 rows containing missing values (`geom_text()`).

library(ggplot2)

unique_positions <- unique(data2$Position)

ggplot(data2, aes(x = "", fill = Position)) +
  geom_bar(width = 1, stat = "count", alpha = 1) +
  coord_polar(theta = "y") +
  labs(title = "Role Distribution", fill = "Position") +
  theme_minimal() +
  theme(
    legend.position = "right",
    legend.box = "vertical",
    plot.title.position = "plot",  
    legend.title.align = 0.5
  ) +
  scale_fill_manual(values = c("Top" = "#66c2a5", "Jungle" = "#fc8d62", "Mid" = "#8da0cb", "ADC" = "#e78ac3", "Support" = "#a6d854")) +
  geom_text(
    aes(label = sprintf("%.1f%%", (..count..)/sum(..count..) * 100)),
    position = position_stack(vjust = 0.5),
    stat = "count",
    vjust = 0.5,
    hjust = 0.5,
    color = "white",
    size = 4 
  ) +
  theme_light() +
  theme(legend.position = "right") +
  guides(fill = guide_legend(title = "Position")) +
  expand_limits(y = c(0, 1))
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

library(ggplot2)
library(plotly)
## Warning: package 'plotly' was built under R version 4.2.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
plot_data <- ggplot(data2, aes(x = gamedur)) +
  geom_line(aes(y = Wrgame, color = "WinRate"), size = 1.5) +  
  geom_point(aes(y = Wrgame, color = "WinRate"), size = 3) +    
  geom_smooth(aes(y = Wrgame, color = "Trend"), method = "loess", se = FALSE, size = 1.2) +  
  labs(title = "WinRate vs Game Duration",
       x = "Game Duration (minutes)",
       y = "WinRate (%)") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid = element_line(color = "gray", linetype = "dotted"),  
        panel.background = element_rect(fill = "white")) +  
  scale_color_manual(values = c("WinRate" = "#0072B2", "Trend" = "#009E73", "Data Points" = "#D55E00"),
                     guide = guide_legend(title = NULL))  
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
plotly_plot <- ggplotly(plot_data, tooltip = c("y"))
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 60 rows containing non-finite values (`stat_smooth()`).
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : Chernobyl! trL>n 6

## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : Chernobyl! trL>n 6
## Warning in sqrt(sum.squares/one.delta): NaNs produced
plotly_plot
library(plotly)

data2$GPM <- data2$GoldEarned / data2$GameDuration
data2$Champion <- as.factor(data2$Champion)

filtered_data <- data2[data2$GamesPlayed >= 10, ]

animated_chart <- plot_ly(
  type = 'scatter',
  mode = 'markers',
  x = ~GameDuration,
  y = ~GPM,
  marker = list(
    size = ~GoldEarned / 1000,  
    color = ~Champion
  ),
  frame = ~GameDuration,
  colors = 'Set1',
  data = filtered_data  
) %>%
  layout(
    xaxis = list(title = "Game Duration"),
    yaxis = list(title = "Gold Per Minute"),
    showlegend = TRUE,
    legend = list(title = "Champion"),
    title = "GPM after 20 min, across all champions played",  # Add the title
    updatemenus = list(
      list(
        type = "buttons",
        showactive = FALSE,
        x = 1.05,
        y = 0.95,
        buttons = list(
          list(
            label = "Play",
            method = "animate",
            args = list(NULL, list(frame = list(duration = 100, redraw = TRUE), fromcurrent = TRUE))
          )
        )
      )
    )
  )

animated_chart