## Loading required package: sp
## Checking rgeos availability: TRUE
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
## Reading layer `TWN_adm2' from data source `C:\Users\Tjlee\Desktop\weather\TWN_adm\TWN_adm2.shp' using driver `ESRI Shapefile'
## Simple feature collection with 22 features and 11 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 116.71 ymin: 20.6975 xmax: 122.1085 ymax: 25.63431
## geographic CRS: WGS 84
## [1] "ID_0" "ISO" "NAME_0" "ID_1" "NAME_1" "ID_2"
## [7] "NAME_2" "TYPE_2" "ENGTYPE_2" "NL_NAME_2" "VARNAME_2" "geometry"
## [1] Kaohsiung City <NA> Taipei City Changhwa Chiayi
## [6] Hsinchu Hualien Ilan Kaohsiung Keelung City
## [11] Miaoli Nantou Penghu Pingtung Taichung City
## [16] Taichung Tainan City Tainan Taipei Taitung
## [21] Taoyuan Yunlin
## 21 Levels: Changhwa Chiayi Hsinchu Hualien Ilan Kaohsiung ... Yunlin
# percents votes received by the DDP party
# hand code data from wiki
# order by names of administrative unit
# attach the data to map data
tw$gvotes <- c(53.42, NA, 56.54, 56.49, 54.81, 35.21, 25.94,
52.53, 53.42, 56.77, 53.18, 42.37, 55.65,
55.13, 54.68, 44.68, 57.72, 57.72, 53.46,
40.50, 55.85, 55.81)
# green or blue by 50 percent votes
gcol <- ifelse(tw$gvotes > 50.0, "green", "blue")
# plot
plot(tw, col=gcol)
## Warning: plotting the first 9 out of 12 attributes; use max.plot = 12 to plot
## all
