Torvaney / ggsoccer

Plot soccer event data in R/ggplot2
https://torvaney.github.io/ggsoccer/
Other
178 stars 27 forks source link

Tracab pitch not showing correctly #36

Open mistpelt7 opened 3 months ago

mistpelt7 commented 3 months ago

Hi,

I am using tracab data to built heat maps in r. When loading the pitch with tracab dimensions the half circle in front of the left goal is not in the right place and appears in the middle of the pitch. I was wondering if there is a way to remove that part or a way to fix it so it's in the right position.

image
Torvaney commented 3 months ago

Hi! Thanks for reporting this - I will look into this issue over the weekend. In the meantime, you should be able to workaround this by rescaling your coordinates to another provider's spec using the rescale_coordinates function:

to_statsbomb <- rescale_coordinates(from = pitch_tracab, to = pitch_statsbomb)

ggplot(your_data) +
  annotate_pitch(dimensions = pitch_statsbomb) +
  geom_point(aes(x = to_statsbomb$x(x), y = to_statsbomb$(y))) +
  theme_pitch()
Torvaney commented 3 months ago

Hey, @mistpelt7, could I ask what version of ggsoccer you are using? If you're not sure, it should be in the output of sessionInfo().

Also, would you be able to make a reprex with your issue? When I run the following code, I don't see the same issue:

library(ggsoccer)
library(ggplot2)

ggplot() +
  annotate_pitch(dimensions = pitch_tracab) +
  theme_pitch()

Created on 2024-05-29 with reprex v2.0.2

mistpelt7 commented 3 months ago

Hi @Torvaney I am on version 0.1.7 which appears to be the latest version according to R.

Here is the r code for the plot. I included all the packages I am using for my plot incase one of them is interfering with it. Thanks for your help!

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(jsonlite)
library(tidyr)
library(nplyr)
library(tidyverse)
library(ggplot2)
library(viridis)
#> Loading required package: viridisLite
library(ggsoccer)

ggplot()+
  annotate_pitch(dimensions = pitch_tracab)

Created on 2024-05-29 with reprex v2.1.0

Torvaney commented 3 months ago

Got it - thanks. I can reproduce it on 0.1.7.

CRAN is lagging a bit behind the Github version. If you devtools::install_github("torvaney/ggsoccer"), it should solve your issues.