Reputation: 652
I am attempting to plot circles with a defined radius onto a raster image. I have successfully plotted my raster and put points onto the image:
# open image to save
png("RasterImage.png",
width=10, height=10, units="in", res=144)
# plot raster
plot(VI.SOS.mean, main="VI Mean SOS",
col=terrain.colors(length(seq(100,220,20))-1), axes=F, breaks=seq(100,200,20))
# add points
points(sensors$X, sensors$Y)
# close png file
dev.off()
This is what the resulting image looks like:
The pixels in my raster are 30 m:
class : RasterLayer
dimensions : 2871, 3205, 9201555 (nrow, ncol, ncell)
resolution : 30, 30 (x, y)
extent : 254265, 350415, 4731885, 4818015 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=16 +datum=WGS84 +units=m +no_defs
data source : in memory
names : layer
values : 38.6, 309 (min, max)
What I would like to do is put a circle with radius x (for example, 300 m) at each of the points. I can manually do this by messing with the size of the points (using cex
, for example), but if I either change the dimensions of the image or crop my raster, then the circles are no longer the correct size. Is there a way to put circles on the map using the units defined in the raster?
Thanks!
Upvotes: 2
Views: 970
Reputation: 47081
You can try this:
library(dismo)
cs <- circles(sensors[, c('X','Y')], d=150)
plot(VI.SOS.mean)
plot(polygons(cs), add=TRUE)
Overlapping circles are merged. If you do not want that, you can use the internal function dismo:::.generateCircles
pls <- dismo:::.generateCircles(sensors[, c('X','Y')], d=150, lonlat=FALSE, crs=NA)
plot(pls, add=TRUE)
Upvotes: 3