I'm working on making shot charts for basketball. I need to figure out how to actually draw the outline of a basketball court in the background. Any ideas?
You may notice that we sometimes reference 'ggplot2' and sometimes 'ggplot'. To clarify, 'ggplot2' is the name of the most recent version of the package. However, any time we call the function itself, it's just called 'ggplot'.
To add an extra point to scatterplot using ggplot2, we can still use geom_point function. We just need to use aes function for quoting with new values for the variables, also we can change the color of this point using colour argument.
The basic steps behind creating a plot with ggplot2 are: Create an object of the ggplot class, typically specifying the data and some or all of the aesthetics; Add on geoms and other elements to create and customize the plot, using + .
To remove a particular panel grid, use element_blank() for the corresponding theme argument. For example to remove the major grid lines for the x axis, use this: p + theme(panel.
The following code was used to get this image:
ggplot(shots, aes(X,Y)) + stat_binhex(binwidth=c(3,3)) + geom_point(size=3, alpha=0.5, aes(color=RESULT), position="jitter") + coord_equal() + theme_grey() + opts(title="Golden State Warriors 2012 Shot Chart") + geom_path(data=ft_line, aes(x,y), colour="white", size=2) + geom_path(data=court, aes(x,y), colour="white", size=2)
The data in the geom_path commands contains the (x,y) coords for the white court diagram.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With