Created
January 25, 2014 16:03
-
-
Save gghatano/8618580 to your computer and use it in GitHub Desktop.
fastball count (2013)
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
library(pitchRx) | |
library(ggplot2) | |
library(data.table) | |
library(dplyr) | |
# データ取得 | |
# data = scrapeFX("2013-01-01", "2013-10-01") | |
# 取得済みデータの利用 | |
# data <- fread("2013.csv") | |
# 公式戦のデータを利用 | |
data <- subset(data, sv_id != "NA") | |
# 直球系ボールフラグ変数を追加 | |
data$F_flag <- ifelse(data$pitch_type %in% c("FF", "FS"), 1, 0) | |
#投手名とカウントでデータを分割 | |
data_count <- data %.% group_by(pitcher_name, count) %.% | |
dplyr::summarise(pitches = length(pitch_type), fs = sum(F_flag)) | |
# 直球率を計算 | |
data_count$ratio <- round(with(data_count, fs / pitches), digit = 3) | |
# setkey | |
setkey(data_count, pitcher_name) | |
# subsetするよりも速いらしい | |
pitch_data <- data_count[J("Hiroki Kuroda"),] | |
pitch_data | |
# plot | |
gg <- ggplot(data = pitch_data) + geom_bar(aes(x=count, y = ratio, fill = "red"), alpha = 0.8, stat = "identity") | |
gg <- gg + theme(legend.position = "none") + ggtitle("Hiroki Kuroda") | |
gg <- gg + theme(plot.title = element_text(size = 20, face ="bold")) | |
gg | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment