Representing Snow Deaths on a Balck & White Map

library(HistData)
## Warning: package 'HistData' was built under R version 3.3.3
library(ggmap)
## Warning: package 'ggmap' was built under R version 3.3.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.2
data("Snow.deaths")
data("Snow.streets")

plot(Snow.deaths[,c("x","y")], col="red", pch=19, cex=.7)
slist <- split(Snow.streets[,c("x","y")],as.factor(Snow.streets[,"street"]))
invisible(lapply(slist, lines, col="black"))

Download the Dataset

## Download the zip archive of geographical information
download.file(url      = "http://www.rtwilson.com/downloads/SnowGIS_v2.zip",
              destfile = "SnowGIS_v2.zip")

## Unzip
unzip(zipfile = "SnowGIS_v2.zip")

## List files in the unzipped folder
dir(path = "./SnowGIS")
##  [1] "Cholera_Deaths.dbf"          "Cholera_Deaths.prj"         
##  [3] "Cholera_Deaths.sbn"          "Cholera_Deaths.sbx"         
##  [5] "Cholera_Deaths.shp"          "Cholera_Deaths.shx"         
##  [7] "OSMap.tfw"                   "OSMap.tif"                  
##  [9] "OSMap_Grayscale.tfw"         "OSMap_Grayscale.tif"        
## [11] "OSMap_Grayscale.tif.aux.xml" "OSMap_Grayscale.tif.ovr"    
## [13] "Pumps.dbf"                   "Pumps.prj"                  
## [15] "Pumps.sbx"                   "Pumps.shp"                  
## [17] "Pumps.shx"                   "README.txt"                 
## [19] "SnowMap.tfw"                 "SnowMap.tif"                
## [21] "SnowMap.tif.aux.xml"         "SnowMap.tif.ovr"
library(ggmap)
library(maptools)
## Warning: package 'maptools' was built under R version 3.3.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 3.3.3
## Checking rgeos availability: FALSE
##      Note: when rgeos is not available, polygon geometry     computations in maptools depend on gpclib,
##      which has a restricted licence. It is disabled by default;
##      to enable gpclib, type gpclibPermit()
library(rgdal)
## Warning: package 'rgdal' was built under R version 3.3.3
## rgdal: version: 1.2-5, (SVN revision 648)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.0.1, released 2015/09/15
##  Path to GDAL shared files: C:/Users/vijay.baskaran.RUB/Documents/R/win-library/3.3/rgdal/gdal
##  Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]
##  Path to PROJ.4 shared files: C:/Users/vijay.baskaran.RUB/Documents/R/win-library/3.3/rgdal/proj
##  Linking to sp version: 1.2-4
library(maptools)
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.3.3
GDALinfo("./SnowGIS/OSMap.tif")
## Warning: statistics not supported by this driver
## rows        1053 
## columns     1169 
## bands       1 
## lower left origin.x        528765 
## lower left origin.y        180466 
## res.x       1 
## res.y       1 
## ysign       -1 
## oblique.x   0 
## oblique.y   0 
## driver      GTiff 
## projection  +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000
## +y_0=-100000 +datum=OSGB36 +units=m +no_defs 
## file        ./SnowGIS/OSMap.tif 
## apparent band summary:
##   GDType hasNoDataValue NoDataValue blockSize1 blockSize2
## 1   Byte           TRUE         255        128        128
## apparent band statistics:
##   Bmin Bmax Bmean Bsd
## 1    0  255    NA  NA
## Metadata:
## AREA_OR_POINT=Area
OSMap <- readGDAL("./SnowGIS/OSMap_Grayscale.tif")
## ./SnowGIS/OSMap_Grayscale.tif has GDAL driver GTiff 
## and has 1070 rows and 1169 columns
par(mar = c(0,0,0,0))
image(OSMap, col = grey(1:500/1000))

getinfo.shape("./SnowGIS/Cholera_Deaths.shp")
## Shapefile type: Point, (1), # of Shapes: 250
map1 <- get_map(c(-.137,51.513), zoom=16)
london_main <- ggmap(map1)

Assigning the Cordinates of Deaths & Pumps Variables from the Dataset

setwd("C:/Users/vijay.baskaran.RUB/Desktop/Personal/Harriburg Unive/DATA VIZ/Mapping/SnowGIS")
deaths <- readShapePoints("Cholera_Deaths")
pumps <- readShapePoints("Pumps")


df_deaths <- data.frame(deaths@coords)
df_pumps <- data.frame(pumps@coords)

tmp <- rbind(df_deaths, df_pumps)
tmp$type <- c(rep('death', times=dim(df_deaths)[1]),
rep('pump', times=dim(df_pumps)[1]))

coordinates(df_deaths)=~coords.x1+coords.x2
proj4string(df_deaths)=CRS("+init=epsg:27700") 
df_deaths = spTransform(df_deaths,CRS("+proj=longlat +datum=WGS84"))
df=data.frame(df_deaths@coords)
lng=df$coords.x1
lat=df$coords.x2


coordinates(tmp)=~coords.x1+coords.x2
proj4string(tmp)=CRS("+init=epsg:27700")
tmp = spTransform(tmp, CRS("+proj=longlat +datum=WGS84"))
tmp <- data.frame(tmp@coords, type=tmp@data$type)

Plot Map

snow.plot <- london_main
snow.plot

Plot Cholera- Pump Dataset on a Map

london_main +
geom_point(mapping=
aes(x=coords.x1, y=coords.x2, col=type, size = 10),
data=tmp)

Adding Density Lines

snow.plot_density <- snow.plot + geom_density2d(data = tmp[tmp$type ==
"death", ], aes(x = coords.x1, y = coords.x2),
size = 0.3)
snow.plot_density

Adding Color Gradient

snow.plot_Colordensity <- snow.plot_density + stat_density2d(data = tmp[tmp$type ==
"death", ], aes(x = coords.x1, y = coords.x2,
fill = ..level.., alpha = ..level..),
size = 0.01, bins = 16, geom = "polygon") +
scale_fill_gradient(low = "red",
high = "red", guide = FALSE) +
scale_alpha(range = c(0, 0.3), guide = FALSE)
snow.plot_Colordensity