I'm having a problem exporting a density im from spatstat to a file format readable by ArcGIS. Here's my code
library(raster)
library(spatstat)
library(maptools)
library(sp)
# make a spatstat ppp with California boundary as window
ca <- readShapePoly("ca.shp")
o3 <- readShapePoints("o3.shp")
o3 <- as(o3, "SpatialPoints")
o3p <- as.ppp(o3)
o3p$window <- as.owin(ca)
# calculate density
d.o3p <- density.ppp(o3p)
which all works fine. But when I attempt to export to an ascii raster file
writeRaster(raster(d.o3p), filename="grid.asc", format="ascii", NAflag=-9999)
I get this problem
Error in .startAsciiWriting(x, filename, ...) :
x has unequal horizontal and vertical resolutions. Such data cannot be
stored in arc-ascii format
The data I'm using are for the state of California, and so the aspect ratio is not 1. So... how do I make the density im have square pixels?