R 如何在ggplot2中创建价格地理热图?

R 如何在ggplot2中创建价格地理热图?,r,ggplot2,R,Ggplot2,我正试图创建一张热图,它覆盖在华盛顿州金郡地理地图的上方,位于ggplot2。我不能使用密度图,因为我想要一张关于纬度/经度的房价热图。到目前为止,我一直在尝试使用geom_tile,但它只会返回无法绘制我要寻找的图片的小点: library(tidyverse) library(maps) library(scales) library(sf) counties <- st_as_sf(map("county", plot = FALSE, fill = TRUE)) counties

我正试图创建一张热图,它覆盖在华盛顿州金郡地理地图的上方,位于ggplot2。我不能使用密度图,因为我想要一张关于纬度/经度的房价热图。到目前为止,我一直在尝试使用geom_tile,但它只会返回无法绘制我要寻找的图片的小点:

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
展示一个可复制的小例子。首先,你的
aes
中有alpha,这意味着它被分配给了一个不存在的变量,这就是它出现在图例中的原因。而且,至少在样本中,您只有非常小面积的房屋数据。除此之外,您是否希望以某种方式存储数据并制作光栅?或者使用
geom_bin2d
来完成?
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))