如何解决使用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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。