Plotting points in a specific area of a picture

Viewed 52

I would like to plot points on a picture:

I have the following df

x <- c(1,2)
y <- c(10,12)
df <- data.frame(x,y

The following picture - tennis court

enter image description here

 img <- readJPEG("tennis_court.jpg")

And the following code to plot the picture

 ggplot(df, aes(x,y)) + 
 annotation_custom(rasterGrob(img, width=unit(1,"npc"), height=unit(1,"npc")), 
                   -Inf, Inf, -Inf, Inf) +
 stat_bin2d() +
 scale_x_continuous(expand=c(0,0)) +
 scale_y_continuous(expand=c(0,0)) 

This works but I would like to plot the point on a specific area. So let's say I want to plot it in the left service area of the right side of the pitch.

Any thought how I can classify a specific part of the picture so that the points are plotted in that area?

1 Answers
Related