tmap
Zachary Wong
March 9, 2024
March 10, 2024
pacman::p_load(sf, terra, gstat, tmap, viridis, tidyverse)
rfstations <- read_csv("data/aspatial/RainfallStation.csv")
rfdata <- read_csv("data/aspatial/DAILYDATA_202402.csv") %>% select(c(1,5)) %>% group_by(Station) %>% summarise(MONTHSUM = sum(`Daily Rainfall Total (mm)`) )%>% ungroup()
rfdata <- rfdata %>% left_join(rfstations)
rfdata_sf <- st_as_sf(rfdata, coords = c("Longitude", "Latitude"), crs = 4326) %>% st_transform(crs = 3414)
mpsz2019 <- st_read(dsn = "data/geospatial", layer = "MPSZ-2019") %>% st_transform(crs = 3414)
tmap_options(check.and.fix = TRUE) tmap_mode("view") tm_shape(mpsz2019) + tm_borders() + tm_shape(rfdata_sf) + tm_dots(col = 'MONTHSUM') tmap_mode("plot")
grid <- terra::rast(mpsz2019, nrows = 690, ncols = 1075) xy <- terra::xyFromCell(grid, 1:ncell(grid))
coop <- st_as_sf(as.data.frame(xy), coords = c(x,y))