I am trying to create a heat map overlaid on top of a geographic map of King county in Washington state in ggplot2. I cannot use a density map, as I want a heat map of house prices with respect to latitude/longitude. So far, I have been trying to use geom_tile but that returns nothing but small dots that don't paint the picture I'm looking for:
library(tidyverse)
library(maps)
library(scales)
library(sf)
counties <- st_as_sf(map("county", plot = FALSE, fill = TRUE))
counties_wa <- subset(counties, grepl("washington", counties$ID))
theme_set(theme_minimal())
counties_wa <- counties %>%
filter(str_detect(ID, 'washington,'))
counties_wa %>%
filter(str_detect(ID, "king")) %>%
ggplot() + geom_sf() +
geom_tile(data = houses, aes(x = long, y = lat, col = price, alpha = 0.5))
dput:
structure(list(id = c(1175000570, 3626039325, 9274202270, 5694500105,
7011200260, 2768301715, 5694000710, 7935000125, 2264500890, 2767603215
), date = structure(c(1426118400, 1416528000, 1408320000, 1417651200,
1418947200, 1426032000, 1415318400, 1401926400, 1399507200, 1400198400
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), price = c(530000,
740500, 625000, 595000, 485000, 565000, 352950, 440000, 712000,
490000), bedrooms = c(5, 3, 2, 2, 4, 4, 3, 3, 3, 3), bathrooms = c(2,
3.5, 1.5, 2, 2, 3, 1, 1, 1, 2), sqft_living = c(1810, 4380, 1490,
1510, 1400, 2020, 1760, 1050, 1250, 1450), sqft_lot = c(4850,
6350, 5750, 4000, 3600, 4300, 3000, 7500, 4620, 2400), floors = c(1.5,
2, 1.5, 1, 1, 1.5, 1.5, 1, 1.5, 1.5), waterfront = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0), view = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
condition = c(3, 3, 4, 4, 3, 3, 1, 3, 4, 3), grade = c(7,
8, 7, 7, 7, 6, 6, 6, 7, 8), sqft_above = c(1810, 2780, 1190,
1010, 1100, 2020, 1760, 1050, 1150, 1450), sqft_basement = c(0,
1600, 300, 500, 300, 0, 0, 0, 100, 0), yr_built = c(1900,
1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900), yr_renovated = c(0,
1999, 0, 0, 0, 0, 0, 0, 0, 2003), zipcode = c(98107, 98117,
98116, 98103, 98119, 98107, 98103, 98136, 98103, 98107),
lat = c(47.67, 47.6981, 47.5872, 47.6582, 47.6385, 47.6653,
47.6598, 47.5473, 47.651, 47.6726), long = c(-122.394, -122.368,
-122.39, -122.345, -122.37, -122.372, -122.348, -122.396,
-122.341, -122.381), sqft_living15 = c(1360, 1830, 1590,
1920, 1630, 1290, 1320, 1380, 1900, 1450), sqft_lot15 = c(4850,
6350, 4025, 4000, 2048, 3440, 1266, 7500, 4400, 4275), decade = c(1900,
1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -10L))
Output:
ggplot 2 geom_tile output
Is there anything that can be done to resolve this issue?