uwescience / WaterReuseDSSG2024

Drivers-Based Water Reuse Potential project for DSSG summer 2024
https://uwescience.github.io/WaterReuseDSSG2024/
Apache License 2.0
1 stars 1 forks source link

bug: map_utils #75

Closed chayek closed 2 months ago

chayek commented 2 months ago

@npovejsil, @voglerdaniel, @Jihyeonbae, @Mbye20, @atkissoncj (sorry wasn't sure who to address this to) thanks for getting me these files!

I'm getting an error message about the left_join on line 281. I tried to fix it by changing the "by" input (when you give it a vector input, you are telling it to join by two commonly named columns present in both files, whereas, we want it to recognize that it is joining by two columns, one in each file, that have the same values so we need to use "join_by()" and the first one listed has to be the name in the first file)

data_sf <- shapefile %>% left_join(data, by= join_by(shape_key == data_key))

unfortunately, this didn't fix my issue and I am still getting the following error message when I try to run mapper:

<error/rlang_error> Error in sf_column %in% names(g): ! Join columns in x must be present in the data. ✖ Problem with shape_key.

Backtrace: ▆

  1. ├─global mapper(...)
  2. │ └─global map_chloropleth(...) at ~/Water-Reuse-DSSG/mapper.R:41:4
  3. │ └─shapefile %>% ... at ~/Water-Reuse-DSSG/map_utils.R:281:4
  4. ├─dplyr::left_join(., data, by = join_by(shape_key == data_key))
  5. ├─sf:::left_join.sf(., data, by = join_by(shape_key == data_key))
  6. │ └─sf:::sf_join(NextMethod(), attr(x, "sf_column"), suffix[1])
  7. │ └─sf_column %in% names(g)
  8. ├─base::NextMethod()
  9. └─dplyr:::left_join.data.frame(., data, by = join_by(shape_key == data_key))
    1. └─dplyr:::join_mutate(...)
    2. └─dplyr:::join_cols(...)
    3. └─dplyr:::check_join_vars(by$x, x_names, by$condition, "x", error_call = error_call)
    4. └─rlang::abort(bullets, call = error_call)

my column names are entered as strings, and they are correct and indeed present in both files. not sure what the issue is :-(


Uploading the new cleaned files in a folder in GD momentarily. The code I tried to run was:

library(readr) library(tidyverse) library(tigris)

tell tigris to cache Census shapefile downloads

options(tigris_use_cache = FALSE)

Set working directory

workdir <- "C:/Users/carol/Documents/Water-Reuse-DSSG" setwd(workdir)

folder for saving figures and tables

image_folder <- "Analysis/Graphics/"

only run next line if you haven't created the folder yet

dir.create(image_folder)

drought_risk_path <- "Cleaned at Exisiting Scale/drought_risk.csv"

load cleaned multiyear drought risk data

drought_risk <- read.csv(drought_risk_path) %>%

correct county fips format to match tigris shapefile called

mutate(FIPS = str_pad(FIPS, 5, side = "left", pad = "0"))

mapper(drought_risk, counties(), variable_name = "NDC2NDI", data_key = "FIPS", shape_key = "GEOID", plot = "choropleth", map_path = image_folder)

chayek commented 2 months ago

cleaned data folder link on GD: https://drive.google.com/drive/folders/1efz_Qq7sWOxRPs_RlrxXOdNOCFvS-8Qu?usp=drive_link

cleaned data file link on GD: https://drive.google.com/file/d/1x6tSossxL1WWUTPLOyDYTM6b2_kCnFWA/view?usp=drive_link