We can visualize two variables as different layers by adding them together. Try clicking on the different layers (use the layer button in the top left).
We can also plot the various factors of ADIs for each county:
or_counties_2023 <- fulldata |> dplyr::filter(state =="Oregon") |> dplyr::filter(year ==2023)or_counties_2022 <- fulldata |> dplyr::filter(state =="Oregon") |> dplyr::filter(year ==2022)# Function to make mini data frames of each row for geom_bar()select_adi_vars <-function(x){ x |>select(geoid, adi, county, financial_strength, economic_hardship_and_inequality, Educational_Attainment) |>pivot_longer(cols=-c(geometry, geoid, county), names_to ="variable", values_to ="value") }# apply function to each row of data frameor_counties_adi <- or_counties_2022 |>rowwise() |>select_adi_vars()## cycle over the geoids and make plots for eachor_plot_data <-map(unique(or_counties_adi$geoid), function(x){ county_name <- or_counties_adi |>filter(geoid == x) |>select(county) |>slice(1) or_counties_adi |>filter(geoid == x) |>ggplot() +aes(x=variable, y=value, fill=variable)+geom_bar(stat="identity", show.legend=FALSE) +ggtitle(county_name) +ylim(0, 150) +theme(axis.text.x =element_text(angle =45)) +scale_x_discrete(labels=c("adi"="ADI", "Educational_Attainment"="Edu","economic_hardship_and_inequality"="Hard", "financial_strength"="Money" ))})mapview(or_counties_2022, zcol ="percent_lacking_plumbing", popup=leafpop::popupGraph(or_plot_data), legend=FALSE)
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_bar()`).