View source: R/mlb_xy_transformation.R
mlbam_xy_transformation | R Documentation |
Transforms data in the hc_x, hc_y
coordinates provided by
MLBAM. The resulting coordinate system is in units of feet, and
has home plate as x=0, y=0
and the y
coordinate
increases toward the pitcher's mound.
mlbam_xy_transformation(data, x = "hc_x", y = "hc_y", column_suffix = "_",
scale = 2.495671)
data |
a |
x |
a character containing the name of the |
y |
a character containing the name of the |
column_suffix |
character. The transformed data will be named according
to the |
scale |
numeric The scale to multiply the transformed data by. The default
sets pixel 51 and sets it to the y-location of second base, |
The data are transformed according to x -> scale * (x - 125) ; y -> scale * (199 - y)
data.frame
. A copy of the input data.frame
with the
transformed data appended
set.seed(101)
batted_ball_data = data.frame(hc_x = rnorm(20, 125, 10), hc_y=rnorm(20, 100, 20))
# append transformed x, y data
transformed_data1 = mlbam_xy_transformation(batted_ball_data)
# overwrite the x, y data with transformed values
transformed_data2 = mlbam_xy_transformation(batted_ball_data, column_suffix="")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.