library(raster)
## Loading required package: sp
library(rgdal)
## 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/Tjlee/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/Tjlee/Documents/R/win-library/3.6/rgdal/proj
##  Linking to sp version: 1.4-1
pacman::p_load(rgdal)
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(tmap)

tw <- st_read("TOWN_MOI_1090324.shp")
## Reading layer `TOWN_MOI_1090324' from data source `C:\Users\Tjlee\Desktop\weather\TOWN_MOI_1090324.shp' using driver `ESRI Shapefile'
## Simple feature collection with 368 features and 7 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 114.3593 ymin: 10.37135 xmax: 124.5611 ymax: 26.38528
## geographic CRS: TWD97
twt <- tw[tw$COUNTYNAME == "臺北市", ]
tmap::qtm(twt) +
  tmap::tm_shape(shp=twt) +
  tmap::tm_text("TOWNNAME", 
                fontfamily="STKaiti")
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

twn <- tw[tw$COUNTYNAME == "臺南市", ]
tmap::qtm(twn) +
  tmap::tm_shape(shp=twn) +
  tmap::tm_text("TOWNNAME", 
                fontfamily="STKaiti")

## I went to taipei and tainan

kh.map <- tw[tw$COUNTYNAME == "高雄市",]
head(kh.map)
## Simple feature collection with 6 features and 7 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 120.2558 ymin: 22.50068 xmax: 120.3989 ymax: 22.75625
## geographic CRS: TWD97
##     TOWNID TOWNCODE COUNTYNAME TOWNNAME           TOWNENG COUNTYID COUNTYCODE
## 18     E11 64000110     高雄市   小港區 Xiaogang District        E      64000
## 156    E01 64000010     高雄市   鹽埕區 Yancheng District        E      64000
## 157    E06 64000060     高雄市   新興區  Xinxing District        E      64000
## 158    E07 64000070     高雄市   前金區  Qianjin District        E      64000
## 159    E09 64000090     高雄市   前鎮區 Qianzhen District        E      64000
## 189    E04 64000040     高雄市   楠梓區    Nanzi District        E      64000
##                           geometry
## 18  MULTIPOLYGON (((120.3044 22...
## 156 MULTIPOLYGON (((120.286 22....
## 157 MULTIPOLYGON (((120.3168 22...
## 158 MULTIPOLYGON (((120.3022 22...
## 159 MULTIPOLYGON (((120.327 22....
## 189 MULTIPOLYGON (((120.3273 22...
library(gridExtra)
library(ggplot2)
g1 <- ggplot(data = kh.map) + geom_sf() + labs(title = "高雄市行政區圖")
g1