0

So I'm using R to plot a list of x and y points of hockey players on a TV screen. However, since the camera is moving, some players will enter the screen and others will leave. In my dataset, I set the x and y coordinates of players not in the frame to (0,0) and if they are in the frame then it is (x,y) with x and y being whatever their coordinates are. However, when I plot there points in ggplot() (using geom_path()) it looks good until they go off screen, then the line jumps all the way to 0,0.

Is there any way that I can add some condition to my code where if the (x,y) coordinates equal 0 at any point, then it doesn't plot it on my graph? It would really clean up my presentation and would help show their tracking when on the ice. Thank you for any help you can provide.

  • 1
    please read the SOP https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610 – B Williams Oct 31 '18 at 17:20
  • 3
    Filter data. For example if your data is in a data table `dt`, something like this should work `ggplot(data = dt[x > 0 & y > 0]) + ...`. – djhurio Oct 31 '18 at 17:21
  • Here is an example https://stackoverflow.com/a/50477176/ – Tung Oct 31 '18 at 17:34

0 Answers0