0

I wonder if it's possible to add the results computed from spatstat (https://cran.r-project.org/web/packages/spatstat/index.html) on the top of a plot created from ggmap .

For example, if I compute a quadratcount how can I add the results on the top of a ggmap.?

Thanks for your help,

Arnaud

Arnaud Geotribu
  • 919
  • 4
  • 11
  • 22
  • 1
    Please read [ask] and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). – Jaap Feb 17 '16 at 10:33
  • try also to provide an example of an output from quadratcount – MLavoie Feb 18 '16 at 09:34

2 Answers2

0

Unfortunately there is no easy way to do this as spatstat uses base graphics and ggplot is fundamentally different. Maybe you could use this answer in this specific case: https://stackoverflow.com/a/10338467/3341769

Community
  • 1
  • 1
Ege Rubak
  • 4,347
  • 1
  • 10
  • 18
  • 1
    Hi Edge, I've already saw this post. Unfortunately, I really want to use spatstat. By chance, do you know how I could display the results computed by spatstat on the top of a map (even not a map from ggmap) ? I just need to display the results on the top of background basemap like OpenStreetMap. Thanks – Arnaud Geotribu Feb 17 '16 at 17:26
  • I agree that this answer isn't great, but it's the best I can do at the moment. The most important fact is that there is no easy way to combine spatstat base graphics with ggmap and ggplot. To plot spatstat results on top of a OpenStreetMap etc. I would guess you need to convert to one of the classes in sp (e.g. using maptools) and then project things correctly there. Sorry for not being more specific, but I don't have a lot of experience with that. – Ege Rubak Feb 22 '16 at 16:58
-1

Finally, I've been able to do what I was looking for. Here is how I did that :

library(raster)
library(ggmap)
library(spatstat)

px  = spatstat::pixellate(myDataset, eps=0.004, what=c("number"))
traj.raster = raster::raster(px)
raster_df = as.data.frame(rasterToPoints(traj.raster))

After getting the result from the pixellate function, I use the raster function to transform it into a raster. Then I transform it into a data frame and then I can easily add it to a ggmap object as a geom_tile object.

Arnaud Geotribu
  • 919
  • 4
  • 11
  • 22