O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Plotting a heatmap over geospatial data

In this example, we will plot a heatmap over the map of Tartu, a city in eastern Estonia, to overlay housing distribution using the latitude and longitude of houses provided in the dataset. First, install and load the require package:

> install.packages(c("ggmap","maps"))> library(ggmap)Next load the housing data containing latitude and longitiude information. Then load the google map of tartu city:> tartu_housing_data <- read.csv("tartu_housing.csv", sep=";")> tartu_map <- get_map(location="tartu", maptype="satellite", zoom = 12)Then overlay the spatial (lat,lon) information over the map:> ggmap(tartu_map, extent='device') +> geom_point(aes(x=lon, y=lat), colour="yellow", alpha=0.1, size=2, data=tartu_housing_data) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required