Adding a background to your ggplot

I really enjoy using the DW-NOMINATE¬†data for examples, as I do here. Sometimes it’s useful to indicate regions in the background of a plot — perhaps two-dimensional regions of interest, perhaps one-dimensional periods in time. It’s not always obvious how to combine data from two data.frames to form one plot in ggplot2, so here is another example.

The trick seems to be that the “second” data frame needs to include all of the same variables as you are using from the “first” data frame (in name, at least — that is, if you are plotting variables called “x”, “y”, and “z” from the “first” data frame, your second data.frame needs to include variables names¬†”x”, “y”, and “z,” even if you’re not plotting with those, and even if they are assigned equal to some arbitrary constant, as in df2$z <- 1).