使用ggmap创建热图,其色标基于数字变量而不是观察值

问题描述

我正在使用ggmap绘制一个纽约出租车行车时间长度的热图。我想将旅行持续时间用作我的色标。我有大量的观测值,它们的经纬度/经度很容易在纽约市地图上绘制。行程持续时间以秒为单位,可用于每次观察。

但是,我正在尝试找出利用类似stat_density2d之类的东西的最佳方法,以绘制出行程持续时间较长的某些区域周围的轮廓(也许可以使用某个区域的平均值?)。我还按月对地块进行分组。

我该怎么做?我的下面代码对此进行了绘制,但我相信我的标度是根据#个观测值而不是数字trip_duration变量来确定的。

library(ggmap)
nyc_map <- get_map(location = c(lon = median(nyc_train2$pickup_longitude),lat = median(nyc_train2$pickup_latitude)),maptype = "terrain",zoom = 13)

pickup_trip_duration_plot <- ggmap(nyc_map) + 
                  geom_density2d(data = nyc_train2,aes(x = pickup_longitude,y = pickup_latitude,fill = trip_duration),size = 0.3) + 
                  stat_density2d(data = nyc_train2,fill = ..level..,alpha = ..level..),size = 0.01,bins = 16,geom = "polygon") + 
                  facet_wrap(~ pickup_month_name,ncol = 3) +
                  scale_fill_gradient(low = "yellow",high = "red") + 
                  ggtitle("Trip Duration Heatmap by Month for Pickup Locations") +
                  scale_alpha(range = c(0,0.3),guide = FALSE)
pickup_trip_duration_plot

# I believe this may have something to do with why I am having plotting issues
# with a numeric value?
Warning message:
Ignoring unkNown aesthetics: fill 

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)