R/esda_helpers.R

Defines functions match_palette get_var

# helper functions


#function used to extract variable from sf dataframe with the variable name
get_var <- function(vname,df) {
  v <- df[vname] %>% st_set_geometry(NULL)
  v <- unname(v[,1])
  return(v)
}


#function used to contruct the correct palette for a set of classification
match_palette <- function(patterns, classifications, colors){
  classes_present <- base::unique(patterns)
  mat <- matrix(c(classifications,colors), ncol = 2)
  logi <- classifications %in% classes_present
  pre_col <- matrix(mat[logi], ncol = 2)
  pal <- pre_col[,2]
  return(pal)
}
morrisonge/spatmap documentation built on June 9, 2020, 1:22 p.m.