# Plot multiple buffers around points

I have three buffer radius sizes

``````radius<-c(1000,700,500)
``````

that I have placed around an array of points (two example points are given here in the file SourcePlace).

What I'd like to do is visualise the three buffer sizes, in different colours, on the same plot. I `attach` the file with the point information, then

``````install.packages("sp")
library(sp)
PlaceCoord <- SpatialPointsDataFrame(data.frame(UTM.Easting,UTM.Northing),data=data.frame(PlaceID,Name,lngYear,IDgroup),proj4string=CRS("+init=epsg:32717"))
ptbufN <- list()
for (i in 1:3) {
ptbufN[i] <- gBuffer(PlaceCoord, width = radius[i], quadsegs = 10)
}
plot(ptbufN[], density=NA, col=1)
plot(ptbufN[], density=NA, col=2)
plot(ptbufN[], density=NA, col=3)
points(PlaceCoord, pch = 20, col = 'red')
``````

What I can't seem to fix is that my polygons are drawn on new plots each time. Maybe there's code to add polygons to existing plots somewhere in ggplot2?

I am sure more elegant ways to perform this task, but I have come to a solution. This requires `sp`, `ggplot2`, and `rgeos`.

As before, I `attach`ed the file with the point information.

`````` PlaceCoord <- SpatialPointsDataFrame(data.frame(UTM.Easting,UTM.Northing),data=data.frame(PlaceID,Name,lngYear,IDgroup),proj4string=CRS("+init=epsg:32717"))

#Establish the three radii of interest

#Create each of the buffers
ptbuf <- list()
for (i in 1:3) {
ptbuf[i] <- gBuffer(PlaceCoord, width = radius[i], quadsegs = 10)
}
firstbuffer<-ptbuf[]
secondbuffer<-ptbuf[]
thirdbuffer<-ptbuf[]
all_buffers<-list(firstbuffer,secondbuffer,thirdbuffer)

#plot
ggplot() +
geom_polygon(data = all_buffers[], aes(x=long, y=lat, group = group), colour="black", fill="black", alpha=0.45)  + # adds the first plot. colour is for the outline, fill is obvious and alpha sets the transparency (1 = opaque) of the polygon
geom_polygon(data = all_buffers[], aes(x=long, y=lat, group = group), colour="red", fill="red", alpha=0.45) + # adds the second plot
geom_polygon(data = all_buffers[], aes(x=long, y=lat, group = group), colour="green", fill="green", alpha=0.45) + # adds the third plo
geom_point(data=SourcePlace,aes(x = UTM.Easting, y = UTM.Northing))+
coord_equal() +
theme(legend.position = "none", title = element_blank(),
axis.text = element_blank())
``````

The group parameter under aes helped me eliminate unwanted lines across my polygons, as discussed here. The output plot, with my entire point array included, looks like this: 