Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Heatmap of touches
x y
2 90
7 15
15 3
18 58
20 20
19 33
36 4
36 5
37 19
38 23
39 24
43 25
44 75
46 59
47 37
47 27
48 27
48 90
49 85
46 85
52 80
54 75
56 55
59 70
55 40
58 9
65 7
60 37
59 40
66 40
64 41
62 50
66 55
67 78
69 74
70 70
71 55
72 56
74 88
75 88
76 85
72 65
70 55
75 50
78 85
95 95
81 21
82 5
95 20
### Soccer Pitch Code
library(ggplot2)
library(RColorBrewer)
cols <- rev(brewer.pal(10, "Spectral"))
ggplot(data=gana) +
stat_density2d(aes(x=as.numeric(x), y=as.numeric(y), z=1, fill = ..density.., na.rm=TRUE), geom="tile", contour = FALSE) +
scale_fill_gradientn(colours=cols) +
theme_minimal() +
geom_segment(aes(x = 0, y = 0, xend = 0, yend = 100), size=1) +
geom_segment(aes(x = 100, y = 0, xend = 100, yend = 100), size=1) +
geom_segment(aes(x = 0, y = 0, xend = 100, yend = 0), size=1) +
geom_segment(aes(x = 0, y = 100, xend = 100, yend = 100), size=1) +
geom_segment(aes(x=50, y= 0, xend = 50, yend = 100), size=1) +
geom_segment(aes(x=0, y=21, xend = 17, yend=21), size=1) +
geom_segment(aes(x=17, y=21, xend = 17, yend=79), size=1) +
geom_segment(aes(x=0, y=79, xend = 17, yend= 79), size=1) +
geom_segment(aes(x=50, y= 0, xend = 50, yend = 100), size=1) +
geom_segment(aes(x=5.8, y= 36.8, xend = 0, yend = 36.8), size=1) +
geom_segment(aes(x=0, y=63.2, xend = 5.8, yend = 63.2), size=1) +
geom_segment(aes(x=5.8, y=36.8, xend = 5.8, yend = 63.2), size=1)+
geom_segment(aes(x=83, y=21, xend=100, yend=21.2), size=1) +
geom_segment(aes(x=83, y=21, xend=83, yend=79), size=1) +
geom_segment(aes(x=83, y=79, xend=100, yend=79), size=1)+
geom_segment(aes(x=100, y=36.8, xend=94.2, yend=36.8), size=1) +
geom_segment(aes(x=94.2, y=36.8, xend=94.2, yend=63.2), size=1) +
geom_segment(aes(x=100, y= 63.2, xend=94.2, yend=63.2), size=1)
Owner

jalapic commented Aug 23, 2015

This code gives this image: gana heatmap

Owner

jalapic commented Aug 23, 2015

Be wary if comparing multiple plots - density needs to be corrected over all plots. Best to have data in one dataframe and use facet_wrap. e.g. comparing two games for the above player looks like this:

gana2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment