{"word_count": 299, "character_count": 2675}
Following my previous post, François (aka @FrancoisKeck) posted a comment mentionning another package I could use to get an interactive map, the rleafmap package. And the heatmap was here easy to include.The first part is still the same, to get the data,&#62; require(rleafmap)&#62; library(sp)&#62; library(rgdal)&#62; library(maptools)&#62; library(KernSmooth)&#62; setwd("/home/arthur/Documents/")&#62; deaths &#60;- readShapePoints("Cholera_Deaths")&#62; df_deaths &#60;- data.frame(deaths@coords)&#62; coordinates(df_deaths)=~coords.x1+coords.x2&#62; proj4string(df_deaths)=CRS("+init=epsg:27700") &#62; df_deaths = spTransform(df_deaths,CRS("+proj=longlat +datum=WGS84"))&#62; df=data.frame(df_deaths@coords)To get a first visualisation, use&#62; stamen_bm &#60;- basemap("stamen.toner")&#62; j_snow &#60;- spLayer(df_deaths, stroke = FALSE)&#62; writeMap(stamen_bm, j_snow, width = 1000, height = 750, setView = c( mean(df[,1]),mean(df[,2])), setZoom = 14)and again, using the + and the - in the top left area, we can zoom in, or out. Or we can do it manually,&#62; writeMap(stamen_bm, j_snow, width = 1000, height = 750, setView = c( mean(df[,1]),mean(df[,2])), setZoom = 16)To get the heatmap, use&#62; library(spatstat)&#62; library(maptools)&#62; win &#60;- owin(xrange = bbox(df_deaths)[1,] + c(-0.01,0.01), yrange = bbox(df_deaths)[2,] + c(-0.01,0.01))&#62; df_deaths_ppp &#60;- ppp(coordinates(df_deaths)[,1],  coordinates(df_deaths)[,2], window = win)&#62; &#62; df_deaths_ppp_d &#60;- density.ppp(df_deaths_ppp,   sigma = min(bw.ucv(df[,1]),bw.ucv(df[,2]))) &#62; df_deaths_d &#60;- as.SpatialGridDataFrame.im(df_deaths_ppp_d)&#62; df_deaths_d$v[df_deaths_d$v &#60; 10^3] &#60;- NA&#62; stamen_bm &#60;- basemap("stamen.toner")&#62; mapquest_bm &#60;- basemap("mapquest.map") &#62; j_snow &#60;- spLayer(df_deaths, stroke = FALSE)&#62; df_deaths_den &#60;- spLayer(df_deaths_d, layer = "v", cells.alpha = seq(0.1, 0.8, length.out = 12))&#62; my_ui &#60;- ui(layers = "topright")&#62; writeMap(stamen_bm, mapquest_bm, j_snow, df_deaths_den, width = 1000, height = 750, interface = my_ui, setView = c( mean(df[,1]),mean(df[,2])), setZoom = 16)The amazing thing here are the options in the top right corner. For instance, we can remove some layers, e.g. to remove the pointsor to change the backgroundTo get an html file, instead of a standard visualisation in RStudio, use&#62; writeMap(stamen_bm, mapquest_bm, j_snow, df_deaths_den, width = 450, height = 350, interface = my_ui, setView = c( mean(df[,1]),mean(df[,2])), setZoom = 16, directView ="browser")which will generate the html table (as well as some additional files actually) above. Awesome, isn't it?