【问题标题】:R - Drawing a baseball strike zone on a graph with ggplot errorsR - 在带有 ggplot 错误的图表上绘制棒球击球区
【发布时间】:2021-08-15 00:24:26
【问题描述】:

下面是我当前的代码

target <- c("BallCalled", "StrikeCalled","StrikeSwinging")
TMData <- Trackman %>% filter(PitchCall %in% target)


plateframe <- 17+2*(9/pi) 
strikezone <- ggplot(NULL, aes(x = px, y = pz)) +
  geom_rect(xmin = -(plateframe/2)/12,
            xmax = (plateframe/2)/12,
            ymin = 1.5, 
            ymax = 3.6, 
            color = "black") +
  coord_equal() +
  scale_x_continuous("Horizontal Plate Location (ft.)", 
                     limits = c(-2,2) +
  scale_y_continuous("Vertical Plate Location (ft.)",
                     limits = c(0,5))

strikezone %+% sample_n(TMData, 264) +
  aes(color = PitchCall) +
  geom_point()

我遇到了不间断的错误。目前,这是我的图表

current

这是棒球数据。我按照教科书的说明画了一个打击区。然后,我在它上面绘制了位置。这是一些示例代码,它是垂直和水平位置

sample code

目前,它不会在我的代码中绘制所有 256 行数据。如果我不包括方框图,它确实绘制得很好。但是,我需要那个盒子。请帮忙

What I want is this, but with the box of the strike zone on top of it.

那只是一个带有 geom_point 的 ggplot(TMData, aes(x = px, y = pa) 图。我不知道为什么我不能将两者重叠。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    我相信您缺少括号来结束您的 scale_x_continuous 函数。它应该在修复后运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      • 2014-06-19
      相关资源
      最近更新 更多