title: How to convert "im" pixel image to raster?
body: <p>I am trying to convert an &quot;im&quot; pixel image I've produced into a raster image. The &quot;im&quot; was created with the following code:</p>
  <pre><code>library(sf)
  library(spatstat)
  library(rgeos)
  library(raster)
  
  # read ebird data 
  ebd_species &lt;- (&quot;ebd_hooded.txt&quot;) %&gt;%
    read_ebd()
  
  # extracting coordinates 
  latitude_species &lt;- ebd_species$latitude
  longitude_species &lt;- ebd_species$longitude
  
  #convert to spatial object
  coordinates1 &lt;- data.frame(x = longitude_species, y = latitude_species) %&gt;% st_as_sf(coords = c(&quot;x&quot;, &quot;y&quot;))
  
  # converting to point pattern data
  coordinates &lt;- as.ppp(coordinates1)
  
  # density image
  a &lt;- density(coordinates,2)
  plot(a)
  </code></pre>
  <p>This is the plot I get:
  <a href="https://i.stack.imgur.com/vGZ9S.png" rel="nofollow noreferrer">plot</a></p>
  <p>What I want to do is convert this into a raster. I wanna then use the coordinates of the ebird data to extract the values of density from the raster.</p>