Hello,
Is it possible to estimate the area under different regions of the map obtained below preferably in % of total area?
Thank you
suppressPackageStartupMessages({
library(tmap)
library(tidyverse)
library(rgdal)
library(rgeos)
library(spatstat)
library(maptools)
library(raster)
library(gstat)
library(sp)
library(gsheet)
})
P_month=gsheet2tbl('https://docs.google.com/spreadsheets/d/1rXB9rG4aRX8Hzyc_O97QcAII9AsiZDlgQ-1JsnMf6ww/edit?usp=sharing')
coordinates(P_month) <- ~lon+lat
proj4string(P_month) <- CRS("+init=epsg:28992")
States=readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_USA_1_sp.rds","rb"))
W <- States %>%
subset(NAME_1%in%c("Alabama","Arkansas", "Florida", "Georgia", "Kentucky", "Louisiana", "Mississippi","Tennessee"))
P_month@bbox <- W@bbox
th <- as(dirichlet(as.ppp(P_month)), "SpatialPolygons")
proj4string(th) <- proj4string(P_month)
grd <- as.data.frame(spsample(P_month, "regular", n=1000000))
names(grd) <- c("X", "Y")
coordinates(grd) <- c("X", "Y")
gridded(grd) <- TRUE
fullgrid(grd) <- TRUE
proj4string(P_month) <- proj4string(P_month)
proj4string(grd) <- proj4string(P_month)
P_month$X <- coordinates(P_month)[,1]
P_month$Y <- coordinates(P_month)[,2]
f.1 <- as.formula(rain ~ X + Y)
var.smpl <- variogram(f.1, P_month, cloud = FALSE)
dat.fit <- fit.variogram(var.smpl, vgm(c("Exp", "Sph", "Gau", "Mat")))
dat.krg <- krige( f.1, P_month, grd, dat.fit)
r.m <- mask(raster(dat.krg), W)
plot(var.smpl, dat.fit)
tm_shape(r.m) +
tm_raster(n=5, midpoint = NA,
title="Rain",
legend.is.portrait = FALSE) +
tm_layout(legend.position=c('left', 'bottom'),
frame = TRUE,
legend.outside = FALSE,
outer.margins=0)