Census Review

I have an API key from the previous class, so I can skip this step. (back-up code below)

census_api_key("YOUR KEY HERE", install=TRUE)

I decided to pull median house value data for tracts in Santa Clara County. The variable is (B25077_001) using get_acs. I also specified geography level, the county, state and the year.

med_house_value <- get_acs(geography = "tract", 
              variables = "B25077_001",
              county= "Santa Clara",
              state = "CA", 
              year = 2023)

view(med_house_value)

Map the data

Preview the map area

scgeo <- tracts("CA", county = 'Santa Clara', progress_bar = FALSE)
qtm(scgeo)

### See what fields are in the map. glimpse(scgeo)
### Mapping the median house value

scmap <- merge(scgeo, med_house_value, by.x = "GEOID", by.y = "GEOID")
qtm(scmap, "estimate")

#adjusting legend
qtm(
  scmap, 
  fill = "estimate",
  fill.breaks = c(0, 500000, 1000000, 1500000, 2000000, 2500000),
  fill.labels = c("<$500K", "$500K–$999K", "$1.0M–$1.49M", "$1.5M–$1.99M", "$2.0M–$2.5M"),
  fill.title = "Median House Value"
)

Interactive map

scpopup <- paste0("<b>COUNTY: ", scmap$NAMELSAD, "</b><br />Median House Value: ", ... = formatC(scmap$estimate, format = "f", big.mark = ",", digits = 0) #formatting numbers
                  )
scpalette <- colorNumeric(palette = "Greens", domain=scmap$estimate)

leaflet(scmap) %>%
  addTiles() %>%
  addPolygons(stroke=FALSE, 
              smoothFactor = 0.2, 
              fillOpacity = .8, 
              popup=scpopup, color= ~scpalette(scmap$estimate))
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'

Change basemap

leaflet(scmap) %>%
  addProviderTiles("CartoDB.Positron") %>%
  addPolygons(stroke=FALSE, 
              smoothFactor = 0.2, 
              fillOpacity = .8, 
              popup=scpopup, color= ~scpalette(scmap$estimate))
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'