Created
December 6, 2018 07:17
-
-
Save sh1ch/ea6d47190369141c33f7d2454709f4bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 先にインストールを済ませる | |
install.packages("devtools") | |
library(devtools) | |
install_github("BillPetti/baseballr") | |
install.packages("ggplot2") | |
install.packages("dplyr") | |
# 大谷選手を調べる例 | |
library(devtools) | |
library(baseballr) | |
library(ggplot2) | |
library(dplyr) | |
# 公式戦の期間を取得 (ざっくり) | |
ohtani2018_all <- scrape_statcast_savant_pitcher("2018-03-29", "2018-09-30", 660271) | |
# 絞り込み (例:不明な球種を消す) | |
ohtani2018_a <- filter(ohtani2018_all, pitch_type != "NA") | |
game3_6 <- subset(ohtani2018_a, grepl( "-0[3-6]-" , ohtani2018_a$game_date)) | |
x_36 <- game3_6$release_pos_x | |
z_36 <- as.numeric(as.character(as.factor(game3_6$release_pos_z))) | |
# 故障前の記録 | |
plot36 <- ggplot(game3_6, aes(y= z_36*30.48, x= x_36*30.48, col= game3_6$pitch_type)) + | |
xlim(-110,-50) + ylim(150,190) + | |
theme_gray(base_family = "HiraKakuProN-W3")+ | |
ggtitle("大谷投手のリリースポイント 2018/03-2018/06")+ | |
labs(colour="球種")+ | |
ylab("高さ(cm)") + xlab("プレート中心からのズレ(cm)")+ | |
geom_point() | |
print(plot36) | |
ggsave(file = "ohtani36.png", plot = plot36) | |
# 故障後の記録 | |
game9 <- subset(ohtani2018_a, grepl( "-0[9]-" , ohtani2018_a$game_date)) | |
x_9 <- game9$release_pos_x | |
z_9 <- as.numeric(as.character(as.factor(game9$release_pos_z))) | |
plot9 <- ggplot(game9, aes(y= z_9*30.48, x= x_9*30.48, col= game9$pitch_type)) + | |
xlim(-110,-50) + ylim(150,190) + | |
theme_gray(base_family = "HiraKakuProN-W3")+ | |
ggtitle("大谷投手のリリースポイント 2018/09(故障後)")+ | |
labs(colour="球種")+ | |
ylab("高さ(cm)") + xlab("プレート中心からのズレ(cm)")+ | |
geom_point() | |
print(plot9) | |
ggsave(file = "ohtani9.png", plot = plot9) | |
# 例2 球速と回転数 | |
# マイルをキロに変換 | |
es_36 <- (game3_6$effective_speed * 1.60934) | |
es_9 <- (game9$effective_speed * 1.60934) | |
rs_36 <- (game3_6$release_spin_rate) | |
rs_9 <- (game9$release_spin_rate) | |
plot36_esrs <- ggplot(game3_6, aes(y= es_36, x= rs_36, col= game3_6$pitch_type)) + | |
xlim(2000,3000) + ylim(120,160) + | |
theme_gray(base_family = "HiraKakuProN-W3")+ | |
ggtitle("大谷投手の球速と回転数")+ | |
labs(colour="球種")+ | |
ylab("球速") + xlab("回転数")+ | |
geom_point() | |
print(plot36_esrs) | |
ggsave(file = "ohtani36_esrs.png", plot = plot36_esrs) | |
plot9_esrs <- ggplot(game9, aes(y= es_9, x= rs_9, col= game9$pitch_type)) + | |
xlim(2000,3000) + ylim(120,160) + | |
theme_gray(base_family = "HiraKakuProN-W3")+ | |
ggtitle("大谷投手の球速と回転数")+ | |
labs(colour="球種")+ | |
ylab("球速") + xlab("回転数")+ | |
geom_point() | |
print(plot9_esrs) | |
ggsave(file = "ohtani9_esrs.png", plot = plot9_esrs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment