raster package: Lines around each cell
You can use rasterToPolygons
:
plot(r, col=c(topo.colors(200)), axes=FALSE, box=FALSE)
plot(rasterToPolygons(r), add=TRUE, border='black', lwd=1)
If you are open to using ggplot2, I offer a possible solution using geom_tile()
. Pixels can be outlined by using the colour
argument to geom_tile
. The drawback is that your data may need some re-formatting to use with ggplot2.
library(ggplot2)
library(reshape2)
dat = melt(volcano[26:40, 26:40])
p = ggplot(dat, aes(x=Var1, y=Var2, fill=value)) +
geom_tile(colour="grey20") +
scale_fill_gradientn(colours = terrain.colors(10))
ggsave("tile_plot.png", plot=p, height=6, width=7, dpi=150)