{"metadata":{"kernelspec":{"name":"ir","display_name":"R","language":"R"},"language_info":{"name":"R","codemirror_mode":"r","pygments_lexer":"r","mimetype":"text/x-r-source","file_extension":".r","version":"3.6.3"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"","metadata":{"_uuid":"051d70d956493feee0c6d64651c6a088724dca2a","_execution_state":"idle"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Let's analyze the nature of MLB players.","metadata":{}},{"cell_type":"markdown","source":"Is there a relationship between height and weight and position?  \n\nIs there any different information on the nature of players from different countries of origin?  \n\nI will analyze these questions while making hypotheses.  ","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# load data","metadata":{}},{"cell_type":"code","source":"library(pacman)\np_load(tidyverse,fs,vroom,glue,janitor,lubridate,ggridges,viridis)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:08:15.25551Z","iopub.execute_input":"2021-06-11T05:08:15.257531Z","iopub.status.idle":"2021-06-11T05:08:16.879085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"options(scipen=10)\noptions(repr.plot.width=15, repr.plot.height=8)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:08:16.881134Z","iopub.execute_input":"2021-06-11T05:08:16.914163Z","iopub.status.idle":"2021-06-11T05:08:16.928318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"file_list <- dir_info(\"../input/mlb-player-digital-engagement-forecasting\") %>% \n  select(path,type,size)\n\nfile_path <- file_list%>%\n  filter(type==\"file\")%>%\n  pull(path)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:08:16.931196Z","iopub.execute_input":"2021-06-11T05:08:16.932585Z","iopub.status.idle":"2021-06-11T05:08:16.984016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"file_path","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:08:16.986016Z","iopub.execute_input":"2021-06-11T05:08:16.987179Z","iopub.status.idle":"2021-06-11T05:08:17.00948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As mentioned in the competition description, some of the data is json nested, so if you simply try to display it, it will overwhelm your memory.","metadata":{}},{"cell_type":"code","source":"awards <- read_csv(file_path[1],col_types = cols()) %>% clean_names()\nexample_sample_submission <- read_csv(file_path[2],col_types = cols()) %>% clean_names()\nexample_test <- read_csv(file_path[3],col_types = cols()) %>% clean_names()\nplayers <- read_csv(file_path[4],col_types = cols()) %>% clean_names()\nseasons <- read_csv(file_path[5],col_types = cols()) %>% clean_names()\nteams <- read_csv(file_path[6],col_types = cols()) %>% clean_names()\ntrain <- read_csv(file_path[7],col_types = cols()) %>% clean_names()","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:08:17.012479Z","iopub.execute_input":"2021-06-11T05:08:17.01385Z","iopub.status.idle":"2021-06-11T05:10:09.916864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#example_sample_submission %>%\n#  separate(date_player_id,c(\"engage\",\"player_id\"))%>%\n#  mutate(player_id = as.numeric(player_id))%>%\n#  left_join(players)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:09.918808Z","iopub.execute_input":"2021-06-11T05:10:09.92Z","iopub.status.idle":"2021-06-11T05:10:09.929118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Prepare information in advance that might be useful.","metadata":{}},{"cell_type":"code","source":"players <- players %>% \n  mutate(today = Sys.Date(),\n         old = today - dob,\n         dob_year = year(dob),\n         dob_month = month(dob),\n         dob_day = day(dob),\n         experience= today - mlb_debut_date\n        )\n\nplayers %>% select(today,old,starts_with(\"dob\"),mlb_debut_date,experience) %>% head(2)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:52:38.048165Z","iopub.execute_input":"2021-06-11T05:52:38.049958Z","iopub.status.idle":"2021-06-11T05:52:38.091491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing about players","metadata":{}},{"cell_type":"code","source":"players %>%\n  count(dob_year) %>%\n  ggplot(aes(x=dob_year,y=n))+\n  geom_col()+\n  labs(title=\"Player’s date of birth [year]\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:09.957213Z","iopub.execute_input":"2021-06-11T05:10:09.958761Z","iopub.status.idle":"2021-06-11T05:10:10.663312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nggplot(aes(x=as.numeric(old)))+\ngeom_density()+\nxlab(\"(today - birth)[day]\")+\nlabs(title=\"Player’s date of birth [days]\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:10.665439Z","iopub.execute_input":"2021-06-11T05:10:10.666711Z","iopub.status.idle":"2021-06-11T05:10:10.99688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Is there a difference in the distribution of ages between countries?","metadata":{}},{"cell_type":"code","source":"players %>%\n  ggplot(aes(x=birth_country,y=as.numeric(old),fill=birth_country))+\n  geom_violin()+\n  ylab(\"a number of days\")+\n  theme(axis.text.x=element_text(angle = 90, hjust = 0))","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:10.999926Z","iopub.execute_input":"2021-06-11T05:10:11.001879Z","iopub.status.idle":"2021-06-11T05:10:12.370636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nggplot(aes(y=birth_country,x=as.numeric(old),fill=birth_country)) + \n  geom_density_ridges()","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:12.373772Z","iopub.execute_input":"2021-06-11T05:10:12.375525Z","iopub.status.idle":"2021-06-11T05:10:13.45076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\n summarise(mean=mean(dob_year),median = median(dob_year),sd = sd(dob_year))","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:13.453004Z","iopub.execute_input":"2021-06-11T05:10:13.454481Z","iopub.status.idle":"2021-06-11T05:10:13.477485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"It seems that most of the players were born in 1991~1993.  \nNow in 2021, they are around 30 years old.  \n\n\nThere is a wide range of ages.  \nDifferent ages will have different lifestyles and ways of thinking.  \nOne way to stratify your players is to give them classes according to their age.  ","metadata":{}},{"cell_type":"markdown","source":"# How long have they been in the MLB since their debut?","metadata":{}},{"cell_type":"code","source":"grid_plot <- seq(0,7500,365)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:13.479463Z","iopub.execute_input":"2021-06-11T05:10:13.480654Z","iopub.status.idle":"2021-06-11T05:10:13.490361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nggplot(aes(x=as.numeric(experience)))+\ngeom_density()+\nscale_x_continuous(breaks = grid_plot) +\ntheme(axis.text.x=element_text(angle = 90, hjust = 0))+\nxlab(\"(today - debutMLB)[day]\")+\nlabs(title=\"Player’s date of experience (days)\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:13.492416Z","iopub.execute_input":"2021-06-11T05:10:13.493559Z","iopub.status.idle":"2021-06-11T05:10:13.872675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nsummarize(mean=mean(as.numeric(experience),na.rm=TRUE)/365,\n         median=median(as.numeric(experience),na.rm=TRUE)/365,\n         sd=sd(as.numeric(experience),na.rm=TRUE)/365He's been playing for 4~5 years.\n         )","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:58:28.422241Z","iopub.execute_input":"2021-06-11T05:58:28.423841Z","iopub.status.idle":"2021-06-11T05:58:28.44749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"they have been playing for 4~5 years.","metadata":{}},{"cell_type":"markdown","source":"# Is there a bias in the date of birth?","metadata":{}},{"cell_type":"code","source":"players %>% \n count(dob_month) %>%\nggplot(aes(x=dob_month,y=n))+\ngeom_col()+\nlabs(title=\"Is there any bias in the month of birth?\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:13.875375Z","iopub.execute_input":"2021-06-11T05:10:13.876896Z","iopub.status.idle":"2021-06-11T05:10:14.212348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There is no bias in the month of birth.  \nMy grandmother said that \"if you are born in summer, you will grow up to be a healthy child who is resistant to the heat\",  \nbut it doesn't seem to true.  \nBecause all the players are energetic people.  \n(I will go teach my grandmother when the epidemic is over.)","metadata":{}},{"cell_type":"code","source":"players %>% \n  count(dob_day) %>%\n  ggplot(aes(x=dob_day,y=n))+\n  geom_col()+\n  labs(title=\"Is there any bias in the day of birth?\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:14.214557Z","iopub.execute_input":"2021-06-11T05:10:14.215814Z","iopub.status.idle":"2021-06-11T05:10:14.532691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The end of the month is understandable because some months have 30 or 31 and some don't.","metadata":{}},{"cell_type":"code","source":"players %>% \n  count(birth_country) %>%\n  ggplot(aes(x=fct_reorder(birth_country,n),y=n))+\n  geom_col()+\n  theme(axis.text.x=element_text(angle = 90, hjust = 0))+\n  xlab(\"\")+\n  labs(title = \"What country are you from?\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:14.536125Z","iopub.execute_input":"2021-06-11T05:10:14.537568Z","iopub.status.idle":"2021-06-11T05:10:14.867483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There seems to be a bias in where they're from.  ","metadata":{}},{"cell_type":"markdown","source":"# A moment of rest\n\nCan I see the people from my country?","metadata":{}},{"cell_type":"code","source":"players %>% \n  filter(birth_country == \"Japan\") %>%\n  arrange(birth_city)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:14.869505Z","iopub.execute_input":"2021-06-11T05:10:14.870715Z","iopub.status.idle":"2021-06-11T05:10:14.91902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Yoshi Tsutsugo** went to high school in Yokohama.  \n**Kohei Arihara** went to high school in his hometown.  \nBoth high schools have produced many baseball players.  \n\n**Masahiro Tanaka** has been good at baseball since I was in junior high school.  \nhe went to a high school in Hokkaido.  \nHokkaido is a cold region and the high school produces many ice hockey players and other athletes,  \n\n**Ichiro Suzuki** is a celebrity that even Japanese people who don't know anything about baseball know.  \nHowever, since he went overseas, people who are not interested in baseball may not know about his activities overseas.  \n\n**Yusei Kikuchi** was born in Iwate Prefecture and went to high school. Many of the graduates of my high school were baseball players.  \n**Shun Yamaguchi** was born in Ooita Prefecture and went to high school. The school is famous for baseball and soccer.  \n\nIs Osaka a famous area overseas?   \n**Kenta Maeda** was born Osaka .He went to PL high school. It is the most famous high school for baseball in Japan.  \n**Yu Darvish** went to a high school in Miyagi. It is a high school with many athletes.  \n\n**Shohei Ohtani** was born in Iwate and went to high school in Iwate. It was the same high school as Yusei Kikuchi.  \n\n**Hirokazu Sawamura** was born in Tochigi and went to a high school there, where several baseball players were born.  \n**Kazuhisa Makita** was born in Shizuoka and went to a high school there, where several baseball players were born.  \n\nKyoto is a nice area with historical buildings and beautiful gardens.\n**Yoshihisa Hirano** was born in Kyoto and went to a high school there. There are few famous people, but the school is full of talented and smart people.  \n\n**Junichi Tazawa** and **Shogo Akiyama** were born in Kanagawa and went to school in Kanagawa. The school has produced several baseball players.  \nJunichi Tazawa, Shogo Akiyama and Yoshi Tsutsugo all went on to different high schools.  ","metadata":{}},{"cell_type":"markdown","source":"End of break\n\n# Focus on three data-rich countries.","metadata":{}},{"cell_type":"markdown","source":"Focus on countries with a large number of MLB playrs.","metadata":{}},{"cell_type":"code","source":"players %>% \n count(birth_country,sort=TRUE) %>%\n head(3)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T06:03:45.504678Z","iopub.execute_input":"2021-06-11T06:03:45.506407Z","iopub.status.idle":"2021-06-11T06:03:45.53826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>% \nfilter(birth_country %in% c(\"USA\",\"Dominican Republic\",\"Venezuela\")) %>%\nmutate(birth_city = fct_lump(birth_city,prop=0.0025)) %>%\nfilter(birth_city != \"Other\") %>%\ncount(birth_country,birth_city)%>%\nggplot(aes(x=birth_city,y=n,fill=birth_country))+\ngeom_col()+\nfacet_wrap(~birth_country,scales=\"free_x\",ncol=1)+\ntheme(axis.text.x=element_text(angle = 90, hjust = 0))+\nlabs(title = \"Top 3 birth_country\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:14.965296Z","iopub.execute_input":"2021-06-11T05:10:14.967217Z","iopub.status.idle":"2021-06-11T05:10:15.830359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>% \nfilter(birth_country %in% c(\"USA\")) %>%\nmutate(birth_city = fct_lump(birth_city,prop=0.005)) %>%\nfilter(birth_city != \"Other\") %>%\ncount(birth_country,birth_city)%>%\nggplot(aes(x=birth_city,y=n,fill=birth_country))+\ngeom_col()+\ntheme(axis.text.x=element_text(angle = 90, hjust = 0))+\nlabs(title = \"No 1 birth_country\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:15.832737Z","iopub.execute_input":"2021-06-11T05:10:15.833995Z","iopub.status.idle":"2021-06-11T05:10:16.242067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>% \nfilter(birth_country %in% c(\"Dominican Republic\")) %>%\nmutate(birth_city = fct_lump(birth_city,prop=0.005)) %>%\nfilter(birth_city != \"Other\") %>%\ncount(birth_country,birth_city)%>%\nggplot(aes(x=birth_city,y=n,fill=birth_country))+\ngeom_col()+\ntheme(axis.text.x=element_text(angle = 90, hjust = 0))+\nlabs(title = \"No 2 birth_country\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:16.244273Z","iopub.execute_input":"2021-06-11T05:10:16.245535Z","iopub.status.idle":"2021-06-11T05:10:16.668432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>% \nfilter(birth_country %in% c(\"Venezuela\")) %>%\nmutate(birth_city = fct_lump(birth_city,prop=0.005)) %>%\nfilter(birth_city != \"Other\") %>%\ncount(birth_country,birth_city)%>%\nggplot(aes(x=birth_city,y=n,fill=birth_country))+\ngeom_col()+\ntheme(axis.text.x=element_text(angle = 90, hjust = 0))+\nlabs(title = \"No 3 birth_country\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:16.670797Z","iopub.execute_input":"2021-06-11T05:10:16.672046Z","iopub.status.idle":"2021-06-11T05:10:17.138225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"They seem to come from many different towns.  \nHowever, large values can be seen in certain towns.  \nThis could be due to the fact that the town is a popular baseball town.  \nThis will be a good feature to use when creating models.  ","metadata":{}},{"cell_type":"markdown","source":"# Focus on the physical characteristics of the players.","metadata":{}},{"cell_type":"code","source":"players %>%\n  mutate(height_cm = height_inches*2.54)%>%\n  ggplot(aes(x=height_cm,y=weight))+\n  geom_point()","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:17.161042Z","iopub.execute_input":"2021-06-11T05:10:17.162214Z","iopub.status.idle":"2021-06-11T05:10:17.562998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=height_cm,y=weight))+\n  stat_density_2d(aes(fill = ..level..),geom = \"polygon\") +\n  scale_fill_viridis()","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:17.58186Z","iopub.execute_input":"2021-06-11T05:10:17.583009Z","iopub.status.idle":"2021-06-11T05:10:18.267569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nmutate(height_cm = height_inches*2.54)%>%\nsummarise(mean_h=mean(height_cm),median_h=median(height_cm),sd_h=sd(height_cm),\n          mean_w=mean(weight),median_w=median(weight),sd_w=sd(weight)\n         )","metadata":{"execution":{"iopub.status.busy":"2021-06-11T06:09:28.559277Z","iopub.execute_input":"2021-06-11T06:09:28.561145Z","iopub.status.idle":"2021-06-11T06:09:28.607244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The average height is 187 centimeters.  \nIs the unit of measure pounds?  \nHis weight is over 90 kilograms.  ","metadata":{}},{"cell_type":"code","source":"players %>%\n  mutate(height_cm = height_inches*2.54)%>%\n  ggplot(aes(x=as.numeric(old),y=as.numeric(experience),color=primary_position_name))+\n  geom_point()+\n  xlab(\"old(age) [days]\")+\n  ylab(\"experience [days]\")+\n  labs(title=\"The relationship between age and experience\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T06:14:11.193531Z","iopub.execute_input":"2021-06-11T06:14:11.195187Z","iopub.status.idle":"2021-06-11T06:14:12.066877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"It is a proportional relationship.  \nI've color-coded it by position, but I don't understand it as it is.  ","metadata":{}},{"cell_type":"code","source":"players %>%\n  mutate(height_cm = height_inches*2.54)%>%\n  ggplot(aes(x=as.numeric(old),y=as.numeric(experience),color=primary_position_name))+\n  geom_point()+\n  facet_wrap(~primary_position_name)+\n  xlab(\"old(age) [days]\")+\n  ylab(\"experience [days]\")+\n  labs(title=\"The relationship between age and experience\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T06:15:21.006818Z","iopub.execute_input":"2021-06-11T06:15:21.008344Z","iopub.status.idle":"2021-06-11T06:15:22.593732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The position seems to have nothing to do with age and experience.  \nThey must be filling each position on a regular basis.  ","metadata":{}},{"cell_type":"markdown","source":"# Does height and weight have anything to do with the number of days of experience?\n\nA possible hypothesis would be that the taller you are, the earlier you debut.","metadata":{}},{"cell_type":"code","source":"players %>%\n  mutate(height_cm = height_inches*2.54)%>%\n  ggplot(aes(x=height_cm,y=as.numeric(experience),color=primary_position_name))+\n  geom_point()+\n  facet_wrap(~primary_position_name)+\n  xlab(\"height [cm]\")+\n  ylab(\"experience [days]\")+\n  labs(title=\"The relationship between height and experience\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:20.665429Z","iopub.execute_input":"2021-06-11T05:10:20.66661Z","iopub.status.idle":"2021-06-11T05:10:22.115933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\n  mutate(height_cm = height_inches*2.54)%>%\n  ggplot(aes(x=weight,y=as.numeric(experience),color=primary_position_name))+\n  geom_point()+\n  facet_wrap(~primary_position_name)+\n  xlab(\"weight [pound]\")+\n  ylab(\"experience [days]\")+\n  labs(title=\"The relationship between weight and experience\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:22.117848Z","iopub.execute_input":"2021-06-11T05:10:22.118993Z","iopub.status.idle":"2021-06-11T05:10:23.706135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=height_cm,y=as.numeric(experience)))+\n  stat_density_2d(aes(fill = ..level..),geom = \"polygon\") +\n  scale_fill_viridis()+\n  xlab(\"height\")+\n  ylab(\"experience [days]\")+\n  labs(title=\"The relationship between height and experience\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=weight,y=as.numeric(experience)))+\n  stat_density_2d(aes(fill = ..level..),geom = \"polygon\") +\n  scale_fill_viridis()+\n  xlab(\"weight\")+\n  ylab(\"experience [days]\")+\n  labs(title=\"The relationship between weight and experience\")","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:23.707997Z","iopub.execute_input":"2021-06-11T05:10:23.709105Z","iopub.status.idle":"2021-06-11T05:10:24.28542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:24.287299Z","iopub.execute_input":"2021-06-11T05:10:24.288413Z","iopub.status.idle":"2021-06-11T05:10:24.845353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Do different countries have different heights?\n\nIn my opinion, the height of Japan is smaller than USA.","metadata":{}},{"cell_type":"code","source":"players %>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=birth_country,y=height_cm,fill=birth_country))+\ngeom_violin()+\ntheme(axis.text.x=element_text(angle = 90, hjust = 0))","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:24.847765Z","iopub.execute_input":"2021-06-11T05:10:24.84901Z","iopub.status.idle":"2021-06-11T05:10:26.020433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=birth_country,y=height_cm,fill=birth_country))+\ngeom_boxplot()+\ntheme(axis.text.x=element_text(angle = 90, hjust = 0))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(y=birth_country,x=height_cm,fill=birth_country)) + \n  geom_density_ridges()","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:26.023288Z","iopub.execute_input":"2021-06-11T05:10:26.025161Z","iopub.status.idle":"2021-06-11T05:10:27.286924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"about weight","metadata":{}},{"cell_type":"code","source":"players %>%\n#mutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=birth_country,y=weight,fill=birth_country))+\ngeom_violin()+\ntheme(axis.text.x=element_text(angle = 90, hjust = 0))","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:27.288913Z","iopub.execute_input":"2021-06-11T05:10:27.290101Z","iopub.status.idle":"2021-06-11T05:10:28.375812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\n#mutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=birth_country,y=weight,fill=birth_country))+\ngeom_boxplot()+\ntheme(axis.text.x=element_text(angle = 90, hjust = 0))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(y=birth_country,x=weight,fill=birth_country)) + \n  geom_density_ridges()","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:28.377751Z","iopub.execute_input":"2021-06-11T05:10:28.378908Z","iopub.status.idle":"2021-06-11T05:10:29.422273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players %>%\nmutate(birth_country = fct_lump(birth_country,prop = 0.004))%>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=height_cm,y=weight,color=birth_country))+\ngeom_point()+\nfacet_wrap(~birth_country)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:29.424182Z","iopub.execute_input":"2021-06-11T05:10:29.425332Z","iopub.status.idle":"2021-06-11T05:10:30.997789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Does their height and weight affect your position?\n\nIt is hard to think that a person with weight is suited for quick movements.","metadata":{}},{"cell_type":"code","source":"players %>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=height_cm,y=weight,color=primary_position_name))+\ngeom_point()+\nfacet_wrap(~primary_position_name)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:30.99974Z","iopub.execute_input":"2021-06-11T05:10:31.000884Z","iopub.status.idle":"2021-06-11T05:10:32.468456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Many infielders are light in weight.\nThey don't seem to need to be tall either.","metadata":{}},{"cell_type":"markdown","source":"# Is there a position that each country excels at?","metadata":{}},{"cell_type":"code","source":"players %>%\nmutate(birth_country = fct_lump(birth_country,prop = 0.004))%>%\nmutate(height_cm = height_inches*2.54)%>%\nggplot(aes(x=height_cm,y=weight,color=primary_position_name))+\ngeom_point()+\nfacet_wrap(~birth_country)","metadata":{"execution":{"iopub.status.busy":"2021-06-11T05:10:32.47046Z","iopub.execute_input":"2021-06-11T05:10:32.471649Z","iopub.status.idle":"2021-06-11T05:10:34.054648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#left_join(awards,players,by = \"player_id\")%>%\n#left_join(teams, by = c(\"award_player_team_id\"=\"id\"))","metadata":{"execution":{"iopub.status.busy":"2021-06-11T07:00:32.225726Z","iopub.execute_input":"2021-06-11T07:00:32.227781Z","iopub.status.idle":"2021-06-11T07:00:32.241606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# under construction\n\nPlease wait a moment.","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}