# 繪圖應用:地圖繪製與物種分布
###### tags: `R教學` `基礎教學`
教學參考:[by Kemushi54](https://kemushi54.github.io/R-basic/sp_and_rgdal.html)
台灣行政地區圖層下載:https://data.gov.tw/dataset/7442
世界圖層下載:https://gadm.org/
**練習檔案:**
1. [台灣行政地區圖層](https://drive.google.com/drive/folders/1xubmyb1_J8OCWLfM7k1HMRuQO3YgXKm6?usp=sharing)
2. [台灣蟑螂分布座標 (來自iNaturalist)](https://drive.google.com/file/d/1KlOqAInbVbsLO3bL-zmOjUcl2TzNTWBZ/view?usp=sharing)
```r=
rm(list=ls())
setwd(choose.dir())
#library("rgeos")
library("rgdal")
#library("geosphere")
TW <- readOGR("mapdata202008310842", "COUNTY_MOI_1090820")
roack <- read.csv("observations-144157.csv")
coordinates(roack) <- ~longitude + latitude
proj4string(roack)<- CRS("+init=epsg:4326")
sort(unique(roack$scientific_name))
Opisthoplatia <- roack[roack$scientific_name == "Opisthoplatia orientalis",]
Periplaneta <- roack[grep("Periplaneta", roack$scientific_name),]
Eucorydia <- roack[roack$scientific_name == "Eucorydia dasytoides",]
German <- roack[roack$scientific_name == "Blattella germanica",]
Supella <- roack[grep("Supella", roack$scientific_name),]
jpeg(filename = "map.jpg", res = 400,
width = 550*10, height = 380*10, pointsize = 20)
plot(TW,
xlim = c(120.0000, 122.0000),
ylim = c(22.00000, 25.50000))
#points(Periplaneta, pch = 19, col = 1)
plot(Periplaneta, pch = 19, col = 1, add=T)
plot(German, pch = 19, col = 2, add=T)
plot(Supella, pch = 19, col = 3, add=T)
plot(Opisthoplatia, pch = 19, col = 4, add=T)
legend(122.5, 25.5, legend = c("(美洲)蟑螂","德國蟑螂","棕帶蟑螂","東方水蠊"),
pch = 19, col = c(1,2,3,4),
bty = "n")
dev.off()
```
