library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.7
## v tidyr 1.1.4 v stringr 1.4.0
## v readr 2.1.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(mdsr)
library(sf)
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
mdsr::CholeraDeaths
## Simple feature collection with 250 features and 2 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 529160.3 ymin: 180857.9 xmax: 529655.9 ymax: 181306.2
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## CRS: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs
## First 10 features:
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## Id Count geometry
## 1 0 3 POINT (529308.7 181031.4)
## 2 0 2 POINT (529312.2 181025.2)
## 3 0 1 POINT (529314.4 181020.3)
## 4 0 1 POINT (529317.4 181014.3)
## 5 0 4 POINT (529320.7 181007.9)
## 6 0 2 POINT (529336.7 181006)
## 7 0 2 POINT (529290.1 181024.4)
## 8 0 2 POINT (529301 181021.2)
## 9 0 3 POINT (529285 181020.2)
## 10 0 2 POINT (529288.4 181031.8)
typeof(mdsr::CholeraDeaths)
## [1] "list"
class(mdsr::CholeraDeaths)
## [1] "sf" "data.frame"
graphics::plot(CholeraDeaths["Count"])
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
dsn <- fs::path(fs::path_wd(), "data", "SnowGIS_SHP")
list.files(dsn)
## [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"
st_layers(dsn)
## Driver: ESRI Shapefile
## Available layers:
## layer_name geometry_type features fields
## 1 Cholera_Deaths Point 250 2
## 2 Pumps Point 8 1
CholeraDeaths <- st_read(dsn, layer = "Cholera_Deaths")
## Reading layer `Cholera_Deaths' from data source
## `C:\projects\info601\info601\materials\13geospatial\class\data\SnowGIS_SHP'
## using driver `ESRI Shapefile'
## Simple feature collection with 250 features and 2 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 529160.3 ymin: 180857.9 xmax: 529655.9 ymax: 181306.2
## Projected CRS: OSGB 1936 / British National Grid
CholeraDeaths
## Simple feature collection with 250 features and 2 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 529160.3 ymin: 180857.9 xmax: 529655.9 ymax: 181306.2
## Projected CRS: OSGB 1936 / British National Grid
## First 10 features:
## Id Count geometry
## 1 0 3 POINT (529308.7 181031.4)
## 2 0 2 POINT (529312.2 181025.2)
## 3 0 1 POINT (529314.4 181020.3)
## 4 0 1 POINT (529317.4 181014.3)
## 5 0 4 POINT (529320.7 181007.9)
## 6 0 2 POINT (529336.7 181006)
## 7 0 2 POINT (529290.1 181024.4)
## 8 0 2 POINT (529301 181021.2)
## 9 0 3 POINT (529285 181020.2)
## 10 0 2 POINT (529288.4 181031.8)
library(ggspatial)
plot(CholeraDeaths["Count"])
ggplot(CholeraDeaths) +
annotation_map_tile(type = "osm", zoomin = 0) +
geom_sf()
## Loading required namespace: raster
## Zoom: 17
## Fetching 16 missing tiles
##
|
| | 0%
|
|==== | 6%
|
|========= | 12%
|
|============= | 19%
|
|================== | 25%
|
|====================== | 31%
|
|========================== | 38%
|
|=============================== | 44%
|
|=================================== | 50%
|
|======================================= | 56%
|
|============================================ | 62%
|
|================================================ | 69%
|
|==================================================== | 75%
|
|========================================================= | 81%
|
|============================================================= | 88%
|
|================================================================== | 94%
|
|======================================================================| 100%
## ...complete!
ggplot(CholeraDeaths) +
geom_sf()
library(ggspatial)
ggplot(CholeraDeaths) +
annotation_map_tile(type = "osm", zoomin = 0) +
geom_sf(aes(size = Count), alpha = 0.7)
## Zoom: 17
cholera_latlong <- CholeraDeaths %>%
st_set_crs(27700) %>%
st_transform(4326)
snow <- ggplot(cholera_latlong) +
annotation_map_tile(type = "osm", zoomin = 0) +
geom_sf(aes(size = Count))
pumps <- st_read(dsn, layer = "Pumps")
## Reading layer `Pumps' from data source
## `C:\projects\info601\info601\materials\13geospatial\class\data\SnowGIS_SHP'
## using driver `ESRI Shapefile'
## Simple feature collection with 8 features and 1 field
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 529183.7 ymin: 180660.5 xmax: 529748.9 ymax: 181193.7
## Projected CRS: OSGB 1936 / British National Grid
pumps_latlong <- pumps %>%
st_set_crs(27700) %>%
st_transform(4326)
snow +
geom_sf(data = pumps_latlong, size = 3, color = "red")
## Zoom: 17
## Fetching 9 missing tiles
##
|
| | 0%
|
|======== | 11%
|
|================ | 22%
|
|======================= | 33%
|
|=============================== | 44%
|
|======================================= | 56%
|
|=============================================== | 67%
|
|====================================================== | 78%
|
|============================================================== | 89%
|
|======================================================================| 100%
## ...complete!