Torvaney / ggsoccer

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

Plot half pitch for shots. #10

Closed davidfombella closed 1 year ago

davidfombella commented 5 years ago

When you use half size to plot shots , it should be required an scale y reverse... however since it is annotate_pitch previous scale this is not possible, if you coord_flip x coordinate is ok but y is flipped

my trial ggplot(goals) + annotate_pitch(colour = "gray70", fill = "gray90") + geom_point(aes(x = x, y = y,colour=team,shape=body.part), size = 4) + theme_pitch()+ coord_flip()+ scale_y_reverse()+ ggtitle("Shotmap", "EPL ")+theme_classic()

Torvaney commented 5 years ago

When you use half size to plot shots , it should be required an scale y reverse

Ah yes, this is correct. I will update the README to reflect this.

if you coord_flip x coordinate is ok but y is flipped

This is weird. From what I can tell, any layers created with geom_rect do not actually get flipped. It may actually be a bug in ggplot2. I think I can workaround by using ggplot2::annotate, but I want to make sure I understand what's going on first.

Thanks for reporting this

Torvaney commented 5 years ago

I've submitted an issue to ggplot2 here.

The workaround for geom_rect -> annotate(geom = "rect", ...) works fine, but getting the pitch circles to behave is a bit tricker. I think the options are as follows:


In the meantime, the easiest way to work around this is probably to alter your input data (which is a bit grim, I know).

goals %>%
  ggplot(aes(x = x, y = 100 - y), ...) +
  # ...