목차

2021 프로야구 각 구단의 연봉 연황을 간략히 구분해 보았다.

1. 용병 국적별 빈도

2. 각 용병의 연봉

3. 구단별 한해 용병 연봉 지출

4. 용병 포지션별 평균 연봉

데이터 불러오기 및 확인.
데이터는 KBO 사이트에서 엑셀로 다운 받은 이후 R파일로 불러오기 하였다
library(readxl)
library(tidyverse)
## ── Attaching packages ────────────────────────────────── tidyverse 1.3.1.9000 ──
## ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.6
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(RColorBrewer)
KRfont2<-theme_set(theme_grey(base_family='NanumGothic'))
import_salary<-read_xlsx("/Users/yongkookkim/Library/Mobile Documents/com~apple~CloudDocs/Baseball_stat_study/import_salary.xlsx",col_names = T)
import_salary<-as.data.frame(import_salary)
head(import_salary)
##   구단               성명   위치 연령(세) 신장(cm) 체중(kg) 계약금($) 연봉($)
## 1   NC  \r\nDrew Rucinski   투수       33      188       91    300000 1300000
## 2   NC \r\nArthur Parsons   투수       29      196       93     80000  320000
## 3   NC  \r\nAaron Altherr 외야수       30      196       97    200000 1100000
## 4 두산  \r\nAriel Miranda   투수       32      188       86    150000  550000
## 5 두산 \r\nWalker Lockett   투수       27      196      102    250000  493000
## 6 두산 \r\nJose Fernandez 내야수       33      178       83    200000  600000
##   총액_달러    총액_원 총액_천만원 입단연도 국적
## 1   1600000 2231904000    223.1904     2019 미국
## 2    400000  557976000     55.7976     2021 미국
## 3   1300000 1813422000    181.3422     2020 미국
## 4    700000  976458000     97.6458     2021 쿠바
## 5    743000 1036440420    103.6440     2021 미국
## 6    800000 1115952000    111.5952     2019 쿠바
str(import_salary)
## 'data.frame':    29 obs. of  13 variables:
##  $ 구단       : chr  "NC" "NC" "NC" "두산" ...
##  $ 성명       : chr  "\r\nDrew Rucinski" "\r\nArthur Parsons" "\r\nAaron Altherr" "\r\nAriel Miranda" ...
##  $ 위치       : chr  "투수" "투수" "외야수" "투수" ...
##  $ 연령(세)   : num  33 29 30 32 27 33 31 34 32 32 ...
##  $ 신장(cm)   : num  188 196 196 188 196 178 188 182 183 191 ...
##  $ 체중(kg)   : num  91 93 97 86 102 83 98 92 92 98 ...
##  $ 계약금($)  : num  300000 80000 200000 150000 250000 200000 250000 300000 0 300000 ...
##  $ 연봉($)    : num  1300000 320000 1100000 550000 493000 600000 500000 500000 525000 700000 ...
##  $ 총액_달러  : num  1600000 400000 1300000 700000 743000 800000 750000 800000 525000 1000000 ...
##  $ 총액_원    : num  2.23e+09 5.58e+08 1.81e+09 9.76e+08 1.04e+09 ...
##  $ 총액_천만원: num  223.2 55.8 181.3 97.6 103.6 ...
##  $ 입단연도   : num  2019 2021 2020 2021 2021 ...
##  $ 국적       : chr  "미국" "미국" "미국" "쿠바" ...

1. 용병 국적별 빈도

national<- import_salary %>% 
  select(성명,구단,총액_달러,총액_천만원,위치,입단연도,국적) %>% 
  group_by(국적) %>% 
  summarise(n=n())

national<- import_salary %>% 
  select(성명,구단,총액_달러,총액_천만원,위치,입단연도,국적) %>% 
  group_by(국적) %>% 
  summarise(n=n())
national
## # A tibble: 6 x 2
##   국적           n
##   <chr>      <int>
## 1 도미니카       1
## 2 멕시코         1
## 3 미국          19
## 4 베네수엘라     5
## 5 캐나다         1
## 6 쿠바           2
ggplot(data=national,aes(x=국적, y=n,fill=국적))+
  geom_col()+
  geom_text(aes(label=n,group=국적),
            hjust=0.5,
            vjust=1.8)+
 theme(plot.title = element_text(face = "bold.italic",
                                  size=20,
                                  color="brown"),
        axis.title = element_text(face = "bold.italic",
                                  size=10,
                                  color="tomato"),
        axis.text = element_text(face = "bold",
                                 size=8,
                                 color="royalblue"),
        panel.background = element_rect(fill = "snow",color ="darkblue"),
        panel.grid.major.y = element_line(color ="gray",linetype="solid"),
        panel.grid.minor.y = element_line(color ="gray",linetype="dashed"),
        legend.position = "right")

2. 각 용병의 연봉

each_salary<- import_salary %>% 
  mutate(총액_단위k=총액_달러/1000) %>% 
  select(성명, 구단,총액_단위k) %>% 
  group_by(성명,구단) %>% 
  as.data.frame()

each_salary
##                       성명 구단 총액_단위k
## 1        \r\nDrew Rucinski   NC       1600
## 2       \r\nArthur Parsons   NC        400
## 3        \r\nAaron Altherr   NC       1300
## 4        \r\nAriel Miranda 두산        700
## 5       \r\nWalker Lockett 두산        743
## 6       \r\nJose Fernandez 두산        800
## 7       \r\nWilliam Cuevas   KT        750
## 8  \r\nOdrisamer Despaigne   KT        800
## 9        \r\nZoilo Almonte   KT        525
## 10        \r\nCasey  Kelly   LG       1000
## 11       \r\nAndrew Suarez   LG        600
## 12       \r\nRoberto Ramos   LG        800
## 13        \r\nEric Jokisch 키움        750
## 14       \r\nJosh A. Smith 키움        500
## 15        \r\nAaron Brooks  KIA       1200
## 16      \r\nDaniel Mengden  KIA        725
## 17     \r\nPreston Tuucker  KIA       1050
## 18         \r\nDan Straily 롯데       1200
## 19     \r\nEnderson Franco 롯데        300
## 20       \r\nDixon Machado 롯데        650
## 21          \r\nBen Lively 삼성        500
## 22      \r\nDavid Buchanan 삼성       1000
## 23         \r\nJose Pirela 삼성        600
## 24      \r\nArthur Lewicki   SK        650
## 25         \r\nWilmer Font   SK       1000
## 26         \r\nJamie Romak   SK        900
## 27    \r\nNicholas Kingham 한화        350
## 28          Ryan Carpenter 한화        400
## 29              Ryon Healy 한화        800
ggplot(data =each_salary,
       aes(x=reorder(성명,-총액_단위k),y=총액_단위k,fill=구단))+
  geom_col()+
  coord_flip()+
  geom_text(aes(label=총액_단위k,group=성명),hjust=1.5)+
   theme(plot.title = element_text(face = "bold.italic",
                                  size=20,
                                  color="brown"),
        axis.title = element_text(face = "bold.italic",
                                  size=10,
                                  color="tomato"),
        axis.text = element_text(face = "bold",
                                 size=8,
                                 color="royalblue"),
        panel.background = element_rect(fill = "snow",color ="darkblue"),
        panel.grid.major.y = element_line(color ="gray",linetype="solid"),
        panel.grid.minor.y = element_line(color ="gray",linetype="dashed"),
        legend.position = "right")+
   labs(title="각 용병의 연봉+계약금",
       x="NAME ",y="총액(단위 $1000)")

3. 구단별 한해 용병 연봉 지출

import_salary1<-import_salary

import_salary1<-import_salary1 %>% 
  select(구단, 총액_달러, 총액_천만원) %>% 
  mutate(총액_단위k=(총액_달러/1000)) %>% 
  group_by(구단) %>% 
  summarise(team_payroll_k=sum(총액_단위k))
import_salary1
## # A tibble: 10 x 2
##    구단  team_payroll_k
##    <chr>          <dbl>
##  1 KIA             2975
##  2 KT              2075
##  3 LG              2400
##  4 NC              3300
##  5 SK              2550
##  6 두산            2243
##  7 롯데            2150
##  8 삼성            2100
##  9 키움            1250
## 10 한화            1550
 ggplot(data = import_salary1,
        aes(x=reorder(구단,team_payroll_k),y=team_payroll_k,fill=구단))+
   geom_col()+
   geom_text(aes(label=team_payroll_k,group=구단),hjust=2)+
   coord_flip()+
   theme(plot.title = element_text(face = "bold.italic",
                                   size=20,
                                   color="brown"),
         axis.title = element_text(face = "bold.italic",
                                   size=10,
                                   color="tomato"),
         axis.text = element_text(face = "bold",
                                  size=,
                                  color="royalblue"),
         panel.background = element_rect(fill = "snow",color ="darkblue"),
         panel.grid.major.y = element_line(color ="gray",linetype="solid"),
         panel.grid.minor.y = element_line(color ="gray",linetype="dashed"),
         legend.position = "top")+
   labs(title="구단별 한해  용병 연봉 지출 PAYROLL",
        x="TEAM NAME ",y="UNIT($1000) ")

4. 용병 포지션별 평균 연봉

position_income<- import_salary %>%
  mutate(총액_단위k=(총액_달러/1000)) %>% 
  select(위치,총액_단위k)%>% 
  group_by(위치) %>% 
  summarise(mean_income_k=mean(총액_단위k)) %>% 
   as.data.frame()
position_income           
##     위치 mean_income_k
## 1 내야수      833.3333
## 2 외야수      808.3333
## 3   투수      758.4000
ggplot(data = position_income,aes(x=위치,y=mean_income_k, fill=위치))+
  geom_col()+
  coord_flip()+
  geom_text(aes(label=round(mean_income_k,digit=2), group=위치),
            hjust=1.1)+
  labs(title="용병 포지션별 평균 연봉",
       x="포지션 ",y="단위($1000) ")+
  theme(plot.title = element_text(face = "bold.italic",
                                  size=20,
                                  color="brown"),
        axis.title = element_text(face = "bold.italic",
                                  size=10,
                                  color="tomato"),
        axis.text = element_text(face = "bold",
                                 size=,
                                 color="royalblue"),
        panel.background = element_rect(fill = "snow",color ="darkblue"),
        panel.grid.major.y = element_line(color ="gray",linetype="solid"),
        panel.grid.minor.y = element_line(color ="gray",linetype="dashed"),
        legend.position = "top")