mlbam_xy_transformation: MLBAM X,Y transformation

View source: R/mlb_xy_transformation.R

mlbam_xy_transformationR Documentation

MLBAM X,Y transformation

Description

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.

Usage

mlbam_xy_transformation(data, x = "hc_x", y = "hc_y", column_suffix = "_",
  scale = 2.495671)

Arguments

data

a data.frame containing x, y coordinates

x

a character containing the name of the x coordinate

y

a character containing the name of the y coordinate

column_suffix

character. The transformed data will be named according to the x, y names, with column_suffix appended.

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, 90 x sqrt{2}

Details

The data are transformed according to x -> scale * (x - 125) ; y -> scale * (199 - y)

Value

data.frame. A copy of the input data.frame with the transformed data appended

Examples

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="")

bdilday/GeomMLBStadiums documentation built on Sept. 24, 2023, 6:02 p.m.