I want to have black lines around each cell of a raster. Below is the example data. I mean, instead of this frame/borderless cells
I want this(cells with borders)
library(raster)
require(graphics)
require(grDevices)
library(colorRamps)
data<-matrix(c(1,0.4,0.5,0.8,-0.9,0.3,-0.89,-0.62,-0.33),ncol=3)
r <- raster(nrows=dim(data)[1],ncols=dim(data)[2],
xmn=-1,xmx=1,ymn=-1,ymx=1)
r[]<-data
setValues(r,factor(data))
plot(r,col=c(topo.colors(200)),axes=FALSE,box=FALSE)
You can use rasterToPolygons
:
plot(r, col=c(topo.colors(200)), axes=FALSE, box=FALSE)
plot(rasterToPolygons(r), add=TRUE, border='black', lwd=1)