This function is called by the resp_combine module and merges response data from a spreadsheet with boundary data from a shapefile into an sf object

resp_combine(
  df,
  df_area_column,
  df_resp_column,
  shape,
  shape_area_column,
  logger = NULL
)

Arguments

df

dataframe. Containing the response data and the name of the administrative area

df_area_column

character. The column name of the dataframe containing the administrative areas

df_resp_column

character. The column name of the dataframe containing the response data

shape

sf. Shapefile containing the boundary data

shape_area_column

character. The column name of the shapefile containing the administrative areas

logger

Stores all notification messages to be displayed in the Log Window. Insert the logger reactive list here for running in shiny, otherwise leave the default NULL

Value

an sf object

Author

Simon Smart simon.smart@cantab.net

Examples

poly_names <- c("A", "B", "C")
df <- data.frame("area" = poly_names, "response" = 1:3)
polygons <- list()
 for(i in 1:3) {
   row <- ceiling(i/10)
   col <- ifelse(i %% 10 != 0, i %% 10, 10)
   xmin = 2*(col - 1); xmax = 2*col; ymin = 2*(row - 1); ymax = 2*row
   polygons[[i]] <- list(cbind(c(xmin, xmax, xmax, xmin, xmin),
                               c(ymax, ymax, ymin, ymin, ymax)))
 }

 polys <- lapply(polygons, sf::st_polygon)
 shape <- sf::st_sf(data.frame(area = poly_names ), geometry = polys)
 combined_shape <- resp_combine(df = df,
                                df_area_column = "area",
                                df_resp_column = "response",
                                shape = shape,
                                shape_area_column = "area")