0

My problem is that I have some thousand POIs and I'd like to make a geo-heatmap of them, preferably in R. Something like this: http://www.geoindex.hu/wp-content/uploads/Nyiregyhaza-vasarloero-100x100-2015.png

I tried ggmap's qmap + geom_point, but that is not really like it, while qmap + stat_bin2d looks similar, but you cannot really control the color and size of the map-elements.

What package should I use? Is there some wrap-around package for Google's Heatmap Layer? Thanks.

lmocsi
  • 550
  • 2
  • 17
  • `library(googleway)` - `add_heatmap()` will do this on a Google map. [example here](https://stackoverflow.com/a/46553980/5977215) – SymbolixAU Oct 08 '17 at 21:37

1 Answers1

1

The ggmap package can do what you want.

# Package source URL: http://cran.r-project.org/web/packages/ggmap/ggmap.pdf
# Data source URL: http://www.geo.ut.ee/aasa/LOOM02331/heatmap_in_R.html

install.packages("ggmap")
library(ggmap)

# load the data
tartu_housing <- read.csv("data/tartu_housing_xy_wgs84_a.csv", sep = ";")

# Download the base map
tartu_map_g_str <- get_map(location = "tartu", zoom = 13)
# Draw the heat map
ggmap(tartu_map_g_str, extent = "device") + geom_density2d(data = tartu_housing, aes(x = lon, y = lat), size = 0.3) + 
  stat_density2d(data = tartu_housing, 
                 aes(x = lon, y = lat, fill = ..level.., alpha = ..level..), size = 0.01, 
                 bins = 16, geom = "polygon") + scale_fill_gradient(low = "green", high = "red") + 
  scale_alpha(range = c(0, 0.3), guide = FALSE)

Code shamelessly stolen from: https://blog.dominodatalab.com/geographic-visualization-with-rs-ggmaps/

Michael Davidson
  • 1,391
  • 1
  • 14
  • 31
  • Great, that's what I've been looking for. Is there a function or package that can reproduce it in a browser? – lmocsi Aug 31 '16 at 13:57
  • Yes. Leaflet, which has a fantastic R package, can make really great interactive (.html) maps like that. See here: http://rmaps.github.io/blog/posts/leaflet-heat-maps/index.html – Michael Davidson Aug 31 '16 at 19:12
  • And how can you show build_time on the heat map, instead of frequencies? – lmocsi Sep 01 '16 at 09:20
  • I don't understand what you mean by build_time? You might have to dig through the documentation for the `leaflet` package though https://rstudio.github.io/leaflet/ or ask a new question. – Michael Davidson Sep 01 '16 at 16:07
  • I meant build_time in the tartu_housing example above. When its not a density function based on the number of POIs, but a heatmap based on some value (eg. build_time of the houses) at that POI. – lmocsi Sep 02 '16 at 08:47