require(rgeos) grid_lines = function(x, y, crs='+proj=longlat +datum=WGS84'){ x1 = round(seq(min(x),max(x),length.out=50),3) y1 = round(seq(min(y),max(y),length.out=50),3) str = character(0) for(i in x) for(j in 2:length(y1)) str = c(str, paste(i, y1[j], ',', i, y1[j-1])) for(i in y) for(j in 2:length(x1)) str = c(str, paste(x1[j], i, ',', x1[j-1], i)) grid = readWKT(paste('MULTILINESTRING((', paste(str, collapse='),('), '))')) grid@proj4string = CRS(crs) grid } ## Example # g = grid_lines(10*(-3:3), 10*(3:7))