The R package spdep has great utilities to define spatial neighbors (e.g. dnearneigh, knearneigh, with a nice vignette to boot), but the plotting functionality is aimed at base graphics.
If you’re hoping to plot spatial neighborhoods as line segments in ggplot2, or ggmap, you’ll need the neighborhood data to be stored in a data frame.
So, to save others some trouble, I thought I’d share a little function that converts a spatial neighbors object (of class nb) to a data frame.
This function is largely an alteration of the existing plotting function for base graphics, plot.nb.