load required packages
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.6.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
require(maps)
## Loading required package: maps
## Warning: package 'maps' was built under R version 3.6.2
library(rgdal)
## Warning: package 'rgdal' was built under R version 3.6.1
## Loading required package: sp
## Warning: package 'sp' was built under R version 3.6.3
## rgdal: version: 1.4-8, (SVN revision 845)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
## Path to GDAL shared files: C:/Users/Owner/Documents/R/win-library/3.6/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
## Path to PROJ.4 shared files: C:/Users/Owner/Documents/R/win-library/3.6/rgdal/proj
## Linking to sp version: 1.3-2
library(sf)
## Warning: package 'sf' was built under R version 3.6.3
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(tmap)
import london shapefile
my_spdf <- readOGR("C:/Users/Owner/Downloads/statistical-gis-boundaries-london/statistical-gis-boundaries-london/ESRI")
## Warning in readOGR("C:/Users/Owner/Downloads/statistical-gis-boundaries-london/statistical-gis-boundaries-london/ESRI"): First layer London_Borough_Excluding_MHW read; multiple layers present in
## C:\Users\Owner\Downloads\statistical-gis-boundaries-london\statistical-gis-boundaries-london\ESRI, check layers with ogrListLayers()
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\Owner\Downloads\statistical-gis-boundaries-london\statistical-gis-boundaries-london\ESRI", layer: "London_Borough_Excluding_MHW"
## with 33 features
## It has 7 fields
#plot(my_spdf, bg = "Black", col = "White")
my_spdf$NAME <- as.character(my_spdf$NAME)
mytm <- tm_shape(my_spdf) + tm_fill() + tm_borders() + tm_legend(title = "London") +
tm_text("NAME", size = .3, col = "black") + tmap_style("classic")
## tmap style set to "classic"
## other available styles are: "white", "gray", "natural", "cobalt", "col_blind", "albatross", "beaver", "bw", "watercolor"
tmap_save(tm = mytm, filename = "LondonTMAP.jpg")
## Warning in png(tmp, width = width, height = height, res = res): 'width=7,
## height=7' are unlikely values in pixels
## Map saved to C:\Users\Owner\Documents\LondonProject2\LondonTMAP.jpg
## Resolution: 2389.896 by 1845.268 pixels
## Size: 7.966321 by 6.150895 inches (300 dpi)
mytm