Loading Packages

library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(tmap)
library(tmaptools)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.0.6     v dplyr   1.0.4
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(raster)
## Loading required package: sp
## 
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
## 
##     select
## The following object is masked from 'package:tidyr':
## 
##     extract
library(fs)
library(rmapshaper)
## Registered S3 method overwritten by 'geojsonlint':
##   method         from 
##   print.location dplyr

Data Setup

JPNoutline <- st_read("C:/Users/Braden/Documents/CSC495/week10files/gadm36_JPN.gpkg", layer = 'gadm36_JPN_0')
## Reading layer `gadm36_JPN_0' from data source `C:\Users\Braden\Documents\CSC495\week10files\gadm36_JPN.gpkg' using driver `GPKG'
## Simple feature collection with 1 feature and 2 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 122.9332 ymin: 24.04542 xmax: 153.9869 ymax: 45.52279
## geographic CRS: WGS 84
JPNoutlinePROJECTED <- JPNoutline %>%
  st_transform(3112)
listfiles<-dir_info("C:/Users/Braden/Documents/CSC495/week10files/tif/") %>%
  filter(str_detect(path, ".tif")) %>%
  dplyr::select(path)%>%
  pull()

worldclimtemp <- listfiles %>%
  stack()
month <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", 
           "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

names(worldclimtemp) <- month

Gather Sample Sites

site2 <- c("Kyoto", "Osaka", 
           "Odawara", "Tokyo", 
           "Naha", "Akita"
           )

lon2 <- c(135.768, 135.497,
          139.166, 139.8394,
          127.679, 140.1025
          )

lat2 <- c(35.01, 34.669,
          35.271, 35.6528,
          26.2123, 39.7200
          )
samples2 <- data.frame(site2, lon2, lat2, row.names="site2")

JPNcitytemp <- raster::extract(worldclimtemp, samples2)

JPNcitytemp
##            Jan       Feb      Mar      Apr      May      Jun      Jul      Aug
## [1,]  7.220000  7.553000 11.24900 17.69800 22.34400 25.44800 29.50300 30.91300
## [2,]  9.479382  9.867010 13.36598 19.77732 24.28247 27.23093 31.18351 32.78969
## [3,] 10.247000 10.410000 12.97300 18.22100 22.21800 24.47300 27.93800 29.73800
## [4,]  9.428947  9.668421 12.47105 18.13158 22.28158 24.56053 28.01842 30.01053
## [5,] 19.213402 19.347422 21.36701 24.09072 26.64845 29.26289 31.35979 31.07835
## [6,]  2.575000  3.093000  6.84700 13.96200 18.96700 22.90200 26.50600 28.64400
##           Sep      Oct      Nov      Dec
## [1,] 26.44500 20.75900 15.33800  9.97800
## [2,] 28.53815 22.88660 17.44124 12.18351
## [3,] 26.09800 21.20200 16.81500 12.61500
## [4,] 26.33947 21.22368 16.50789 12.02895
## [5,] 30.12887 27.68866 24.35258 21.06804
## [6,] 24.21200 18.29800 11.75300  5.69600
JPNcitytemp2 <- JPNcitytemp %>% 
  as_tibble()%>% 
  add_column(Site = site2, .before = "Jan")

JPNoutSIMPLE<-JPNoutline %>%
  ms_simplify(keep=0.05)

Map

JPNtemp <- JPNoutSIMPLE %>%
  crop(worldclimtemp,.)

plot(JPNtemp)