{"word_count": 190, "character_count": 1761}
In my previous post, I discussed how to use OpenStreetMaps (and standard plotting functions of R) to visualize John Snow's dataset. But it is also possible to use Google Maps (and ggplot2 types of graphs).library(ggmap)get_london &#60;- get_map(c(-.137,51.513), zoom=17)london &#60;- ggmap(get_london)Again, the tricky part comes from the fact that the coordinate representation system, here, is not the same as the one used on Robin Wilson’s blog.&#62; library(maptools)&#62; setwd("/cholera/")&#62; deaths &#60;- readShapePoints("Cholera_Deaths")&#62; head(deaths@coords)coords.x1 coords.x20  529308.7  181031.41  529312.2  181025.22  529314.4  181020.33  529317.4  181014.34  529320.7  181007.95  529336.7  181006.0&#62; X &#60;- deaths@coordsor, use d X_deaths.RData. So now, we have to change itdf_deaths &#60;- data.frame(X)library(sp)library(rgdal)coordinates(df_deaths)=~coords.x1+coords.x2proj4string(df_deaths)=CRS("+init=epsg:27700") df_deaths = spTransform(df_deaths,CRS("+proj=longlat +datum=WGS84"))Here, we have the same coordinate system as the one used in Google Maps. Now, we can add a layer, with the points,london + geom_point(aes(x=coords.x1, y=coords.x2),data=data.frame(df_deaths@coords),col="red")Again, it is possible to add the density, as an additional layer,london + geom_point(aes(x=coords.x1, y=coords.x2), data=data.frame(df_deaths@coords),col="red")+geom_density2d(data = data.frame(df_deaths@coords), aes(x = coords.x1, y=coords.x2), size = 0.3) + stat_density2d(data = data.frame(df_deaths@coords), aes(x = coords.x1, y=coords.x2,fill = ..level.., alpha = ..level..),size = 0.01, bins = 16, geom = "polygon") + scale_fill_gradient(low = "green", high = "red",guide = FALSE) + scale_alpha(range = c(0, 0.3), guide = FALSE)&#160;