Descriptive spatial statistics

Calculate the mean center of the following point dataset:

library(spData)
library(sf)
library(dplyr)
library(tmap)
library(haffutils)

cycle_hire

## get x and y as variables
cycle_hire$x <- cycle_hire %>%
  st_coordinates() %>%
  data.frame() %>%
  pull(X) %>%
  unlist()

cycle_hire$y <- cycle_hire %>%
  st_coordinates() %>%
  data.frame() %>%
  pull(Y) %>%
  unlist()

## calculate mean center

## calculate mean center using sf methods

## calculate mean center using haffutils

## calculate weighted mean center of nbikes

## calculate weighted mean center of nempty

Calculate the weighted mean center using the following polygon dataset:

library(tidycensus)
library(tmap)
library(sf)
library(haffutils)

mn_2020 <- get_decennial(geography = "county",
                         state = "MN",
                         variables = c(pop2020 = "P1_001N"),
                         geometry = TRUE,
                         year = 2020,
                         output = "wide",
                         cb = TRUE)

mn_2000 <- get_decennial(geography = "county",
                         state = "MN",
                         variables = c(pop2000 = "P001001"),
                         year = 2000,
                         output = "wide")

mn <- left_join(mn_2020, mn_2000, by = "GEOID")

## simple maps

## calculate change in population

## calculate weighted mean center