Sometimes it is helpful to use a technique of adding a gray semi-transparent layer to an image and then cutting a keyhole into that layer to highlight a certain portion of the image below. Here is an example from a youtube vide:
I do this with plots sometimes but use Inkscape to add a semitransparent layer and then use the eraser to cut a hole in that layer. This (a) looks less than professional (b) requires extra time and a separate program and (c) possible loss in quality.
I want to do it in R. I'm asking about ggplot2 because this is my tool of choice but I think any grid answer would be good (I know base probably has a very different approach).
So here is a MWE where I've added a geom_rect
to show where we'd want to cut the keyhole/window:
ggplot(mtcars, aes(mpg, wt)) +
geom_point(size=3) +
geom_rect(mapping=aes(xmin=20, xmax=25,
ymin=3, ymax=3.3), color="black", alpha=.01)
How can I use R to make a plot that looks something like this: