Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw something in the background of a ggplot?

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?

enter image description here

enter image description here

enter image description here

like image 641
Evan Zamir Avatar asked Oct 09 '12 00:10

Evan Zamir


People also ask

What is the difference between Ggplot and ggplot2?

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'.

How do I add a point in ggplot2?

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.

How to make a plot with ggplot2?

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 + .

How do I get rid of the GREY grid in ggplot2?

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.


1 Answers

enter image description here

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.

like image 175
Evan Zamir Avatar answered Oct 04 '22 16:10

Evan Zamir