League of Legends 数据分析小项目

2018-05-13  本文已影响0人  AIHENJIANDAN
image.png

这是我的第一个数据小项目,(期中考试陆陆续续写了一点,不过都跟猴子搬玉米似的,第二次继续写又不连贯了,所以考完在图书馆蹲了一天总算是把它shut down了 :))那啥,如果有做的不好的地方还请各位见谅,毕竟新手,哈哈。
因为原文是在kaggle上写的,用的英文,就暂时不翻译过来了(对了,数据来自于kaggle数据集 League of Legends.有关于数据集的介绍就不赘述了。


image.png

分割线



Then I will display it from 5 aspects:


Bans


library(tidyverse)
library(RColorBrewer)
library(dplyr)
library(grid)
library(gridExtra)
options(warn = -1)
bans <- read.csv("../input/bans.csv")
head(bans)
image.png
bans <- bans[,-1]
newbans <- bans %>% tbl_df() %>% gather(.,ban_1,ban_2,ban_3,ban_4,ban_5,key = "ban_num",value = "heros") %>% filter(.,heros != "")
head(newbans)
image.png
ggplot(newbans,aes(x=heros,fill=heros))+geom_histogram(stat = "count",binwidth = 20)+coord_flip()+theme(legend.position = "none")+
  facet_wrap(facets = ~Team,scales = "free")
Rplot01.jpeg

we can get some info from this picture.

Numeber of games per League of Legends






leagues <- read.csv("../input/LeagueofLegends.csv")
test <- leagues %>% select(.,League,Year,Season) %>% filter(League == c("MSI","NALCS","LMS","LCK","EULCS")) %>%
  group_by(League,Year) %>% summarise(number = n())
m <- c(RColorBrewer::brewer.pal(12,"Set3"),brewer.pal(3,"Set2"))
z1 <- ggplot(test,aes(x=Year,y = number,fill=League))+geom_histogram(stat = "identity",position = "stack")+
  scale_fill_manual(values = m)+theme(legend.position = "none")
z2 <- ggplot(test,aes(x=reorder(League,-number),y = number,fill=League))+geom_bar(stat = "identity")+scale_fill_manual(values = m)+
  labs(x="League",y="Number of Competitions")+theme(legend.position = "top",legend.text  = element_text(size = 5))
grid.arrange(z1,z2,ncol=2)

image.png

Eh~ In this part, I only choose 5 main Leagues from the data, and I wonder why this data doesn't have LPL competitons? Maybe our country's walls. So we can get some info that LCK league has most competition and NALCS second. But if LPL in data , I think it may have more competitions than NALCS

newleagues <- mutate(leagues,seatype = str_c(leagues$Season,leagues$Type))
newleagues %>% group_by(League,Year,seatype) %>% summarise(number=n()) %>% ggplot(aes(Year,y = League,size  = number,color =seatype))+
  geom_point()+facet_wrap(~seatype)+theme(legend.position = "top",axis.text.y = element_text(size = 8),legend.text=element_text(size=5),legend.key.size = unit(.2, "cm"))
image.png

Compare gamelength in different leagues


p <- leagues %>% select(League,gamelength) %>% filter(League == c("MSI","NALCS","LMS","LCK","EULCS"))
ggplot(p,aes(x = gamelength,colour = League))+geom_density()
image.png
ggplot(p,aes(x = gamelength,fill=League))+geom_density()+facet_wrap(~League)
image.png
ggplot(p,aes(x = League,y = gamelength,fill = League))+geom_boxplot()
image.png

Kills


kills <- read.csv("../input/kills.csv")
#choose my favorite players from the data
players <- c("Faker","Doublelift","Uzi","Rekkles","PraY")
kills %>% mutate(Player = word(kills$Kille,-1)) %>% select(Time,Player) %>% filter(Player %in% players) %>%
ggplot(aes(x =Time,fill= Player))+geom_density(alpha = 0.7)+facet_wrap(~Player,nrow = 5)
image.png

I choose 4 ADCs in 2018 MSI League.(PraY,Rekkles,Uzi,Doublelift) and a so famous person in LOL -faker,then I found almost players start to get Kills from 15 minutes . Before this time, they farmed in themselves' line. And 20~30 min become a most bellicose time to most teams.

Monsters and Structures


monsters <- read.csv("../input/monsters.csv")
monsters  %>% ggplot(aes(x = Type,y =Time,fill=Type))+geom_violin()+coord_flip()+
theme(legend.position = "top",legend.text = element_text(size=8))
image.png
dragon_name <- c("AIR_DRAGON","EARTH_DRAGON","FIRE_DRAGON","WATER_DRAGON")
p1 <- monsters %>% filter(Type == dragon_name) %>% ggplot(aes(x = Type,fill=Type))+geom_histogram(stat = "count")+scale_fill_brewer(4,"Set3")+
theme(legend.position = "top")
p2  <- monsters %>% filter(Type != dragon_name) %>% ggplot(aes(x = Type,fill=Type))+geom_histogram(stat = "count")+scale_fill_brewer(3,"Set3")+
theme(legend.position="top")+coord_flip()
grid.arrange(p1,p2)
image.png
structures <- read.csv("../input/structures.csv")
structures %>% na.omit() %>% mutate(NewTeam = str_sub(Team,1,1)) %>% 
ggplot(aes(Time,colour = NewTeam))+geom_density()+facet_wrap(~Type)+scale_color_manual(values = c("blue","red"),labels = c("blue","red"),name = "Team")+labs(title = "The time distribution of different teams destroy structures")
image.png

something I want to say ...


上一篇下一篇

猜你喜欢

热点阅读