ggsoccer
ggsoccer copied to clipboard
Plot half pitch for shots.
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()
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
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:
- Submit PR/fix to ggplot2 so that it scales
annotation_custom
objects correctly- The ideal solution but probably also the most work involved
- Mark pitch circles with
annotate("point", pch = 21, ...)
- Circles won't really scale properly with plot image size
- Mark pitch circles with
geom_path(data = circle_data(...), ...)
- Circularity not guaranteed (they will generally look oblong)
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), ...) +
# ...