library(mdsr)
library(sp)
plot(CholeraDeaths)
It is probably best to do this in an R Project.
library(rgdal)
download.file("http://rtwilson.com/downloads/SnowGIS_SHP.zip",
dest="SnowGIS.zip", mode="wb")
trying URL 'http://rtwilson.com/downloads/SnowGIS_SHP.zip'
Content type 'application/zip' length 6875824 bytes (6.6 MB)
==================================================
downloaded 6.6 MB
unzip("SnowGIS.zip")
getwd()
[1] "/home/esuess/classes/2019-2020/01 - Fall 2019/Stat651/Presentations/08_spatial"
dsn <- paste0("./SnowGIS_SHP/")
list.files(dsn)
[1] "Cholera_Deaths.dbf" "Cholera_Deaths.prj" "Cholera_Deaths.sbn"
[4] "Cholera_Deaths.sbx" "Cholera_Deaths.shp" "Cholera_Deaths.shx"
[7] "OSMap_Grayscale.tfw" "OSMap_Grayscale.tif" "OSMap_Grayscale.tif.aux.xml"
[10] "OSMap_Grayscale.tif.ovr" "OSMap.tfw" "OSMap.tif"
[13] "Pumps.dbf" "Pumps.prj" "Pumps.sbx"
[16] "Pumps.shp" "Pumps.shx" "README.txt"
[19] "SnowMap.tfw" "SnowMap.tif" "SnowMap.tif.aux.xml"
[22] "SnowMap.tif.ovr"
ogrListLayers(dsn)
[1] "Pumps" "Cholera_Deaths"
attr(,"driver")
[1] "ESRI Shapefile"
attr(,"nlayers")
[1] 2
ogrInfo(dsn, layer = "Cholera_Deaths")
Source: "/home/esuess/classes/2019-2020/01 - Fall 2019/Stat651/Presentations/08_spatial/SnowGIS_SHP", layer: "Cholera_Deaths"
Driver: ESRI Shapefile; number of rows: 250
Feature type: wkbPoint with 2 dimensions
Extent: (529160.3 180857.9) - (529655.9 181306.2)
CRS: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs
LDID: 87
Number of fields: 2
name type length typeName
1 Id 0 6 Integer
2 Count 0 4 Integer
CholeraDeaths <- readOGR(dsn, layer = "Cholera_Deaths")
OGR data source with driver: ESRI Shapefile
Source: "/home/esuess/classes/2019-2020/01 - Fall 2019/Stat651/Presentations/08_spatial/SnowGIS_SHP", layer: "Cholera_Deaths"
with 250 features
It has 2 fields
summary(CholeraDeaths)
Object of class SpatialPointsDataFrame
Coordinates:
min max
coords.x1 529160.3 529655.9
coords.x2 180857.9 181306.2
Is projected: TRUE
proj4string :
[+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m
+no_defs]
Number of points: 250
Data attributes:
Id Count
Min. :0 Min. : 1.000
1st Qu.:0 1st Qu.: 1.000
Median :0 Median : 1.000
Mean :0 Mean : 1.956
3rd Qu.:0 3rd Qu.: 2.000
Max. :0 Max. :15.000
str(CholeraDeaths@data)
'data.frame': 250 obs. of 2 variables:
$ Id : int 0 0 0 0 0 0 0 0 0 0 ...
$ Count: int 3 2 1 1 4 2 2 2 3 2 ...
cholera_coords <- as.data.frame(coordinates(CholeraDeaths))
cholera_coords
cholera_coords %>% ggplot(aes(x = coords.x1, y = coords.x2)) +
geom_point() +
coord_quickmap()