I'm attempting to create a map in R which overlays an artificial geographic boundary (determined by a set of (x, y) points w/ lat and lon values) over a Google Maps image of an area from ggmap. The code I'm using is below.
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 1, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE) +
for (i in 1:3){
geom_segment(data = coords, aes(x = lon[[i]], y = lat[[i]], xend = lon[[(i+1)]], yend = lat[[(i+1)]], alpha = 0.8))
}
Note that coords is a data.frame containing the pertinent lat and lon values, and df is a similar data.frame containing point values; they are both structured properly.
With just one iteration, the above code works fine; the area map appears, the three points I would like to plot appear, and the line drawn between two of them appears as well. However, when I try to perform this action iteratively within a for loop, none of the lines print. I read on a similar post that this is because R's auto-print feature doesn't work within loops, so I tried wrapping the relevant statements in print() functions, but that just returns "NULL" for some reason. I have a feeling I'm making some glaringly obvious mistake but I'm unsure what it is. Thank you in advance!

ggplotlayers on top of each other, and that isn't happening here.geom_pathdoes what I think you're looking for. - camille