Ref: Emerging Hot Spot Analysis
Ref:
Ref:
Static hotspot analysis
library(tidyverse) library(sf) library(openxlsx) library(ggplot2) library(tmap) tmap_mode("view") library(sfhotspot) # Set default work directory setwd("/Users/libingnan/Documents/09-Samsung/12-Polygon-based emerging hotspot analysis") hist <- read.xlsx("epiwatch_monkeypox.xlsx") %>% mutate(PubDate = as.Date(`insert-timestamp`, origin = "1899-12-30")) %>% # filter(PubDate >= as.Date("2020-01-01")) %>% mutate(Longitude = as.numeric(long), Latitude = as.numeric(lat)) %>% drop_na(Longitude, Latitude) %>% # filter(diseases == "covid19") %>% # line below removes diseases with less than 5 occurrences # group_by(diseases) %>% filter(n() >=5) %>% ungroup() %>% #drop_na(diseases) %>% st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326) %>% st_transform(3857) results <- hotspot_classify(data = hist, time = PubDate, period = "1 week", cell_size = 500000, # 500 km #cell_size = 200000, # 200 km quiet = F, params = hotspot_classify_params( nb_dist = 0.1) # default is to use points outside of cell. # changed to minimum distance to reduce confusion ) #autoplot(results) tm_shape(results, name = "Hotspot Detection") + tm_polygons("hotspot_category", title = "Hotspot Category", palette = c("persistent hotspot" = "red", "emerging hotspot" = "orange", "intermittent hotspot" = "yellow", "former hotspot" = "darkgreen", "no pattern" = NA), alpha = 0.7, lwd = 0.8) + tm_shape(hist, name = "Reports") + tm_dots(jitter=0.1)
结果显示:
Emerging hotspot analysis
library(tidyverse) library(sf) library(openxlsx) library(ggplot2) library(tmap) tmap_mode("view") library(sfhotspot) library(sfdep) library(dplyr) # get directories of files df_fp <- system.file("extdata", "bos-ecometric.csv", package = "sfdep") geo_fp <- system.file("extdata", "bos-ecometric.geojson", package = "sfdep") # read in data df <- readr::read_csv(df_fp, col_types = "ccidD") geo <- sf::read_sf(geo_fp) # Create spacetime object called `bos` bos <- spacetime(df, geo, .loc_col = ".region_id", .time_col = "time_period") # conduct EHSA ehsa <- emerging_hotspot_analysis( x = bos, .var = "value", k = 1, nsim = 9 ) # should put geo in the first place, otherwise it will triger the projection error geo_ehsa <- merge(geo, ehsa, by.x=".region_id", by.y="location") # tm_shape: Specify the shape object # tm_polygons: Draw polygons # "clssification" is a column of hotspot_results tm_shape(geo_ehsa, name = "Hotspot Detection") + tm_polygons("classification", title = "Hotspot Category", palette = c("no pattern detected" = "#4576b5"), alpha = 0.7, lwd = 0.8)
结果显示:
标签:tmap,diseases,emerging,library,hotspot,analysis From: https://www.cnblogs.com/alex-bn-lee/p/17203053.html