地图上的可视化协调

时间:2017-05-05 13:28:58

标签: r

我有两个数据框如下:

数据帧提取:

PickUP <- data.frame(pickuplong = c(-73.93909 ,-73.94189 ,-73.93754,-73.91638,-73.92792 ,-73.88634), pickuplat =c(40.84408,40.83841,40.85311,40.84966,40.86284,40.85628)) 

dataframe dropoff:

Dropoff <- data.frame(pickuplong = c(-73.93351 ,-73.93909 ,-73.93909 ,-73.80747,-73.95722,-73.91880), pickuplat =c(40.76621,40.84408,40.85311,40.69951,40.68877,40.75917), Droplong =c(-73.91300,-73.96259 ,-73.94870,-73.93860,-73.93633, -73.90690), Droplat =c(40.77777,40.77488 ,40.78493,40.84463,40.75977,40.77013)) 

我可以在下拉数据框中找到类似于拾取的协调:

 findcoord <-  subset(Dropoff, PickUP$Pickup_longitude %in% Dropoff$Pickup_longitude)

如何在地图上可视化Drop-off数据帧的记录,其中Dropoff数据帧拾取经度和纬度类似于经度和纬度PickUp数据帧? Visualization Expectation

1 个答案:

答案 0 :(得分:0)

当我运行findcoord的示例脚本时,数据框为空。所以我不完全明白你想要什么。我在下面展示的示例脚本是一种使用mapview包可视化空间点数据的方法。我以您的Dropoff数据框为例,创建了一个html交互式地图。在准备好数据框后,您可能会采用相同的策略来绘制数据。

如果您不想要交互式地图,ggmap套餐可能符合您的需求。

# Load packages
library(sp)
library(rgdal)
library(leaflet)
library(mapview)

# Create a column storing ID
Dropoff$ID <- 1:nrow(Dropoff) 

# Separate pickup and drop-off coordinates
Dropoff_p <- Dropoff[, c("ID", "pickuplong", "pickuplat")]
Dropoff_d <- Dropoff[, c("ID", "Droplong", "Droplat")]

# Create spatial point data frame for Dropoff_p and Dropoff_d
coordinates(Dropoff_p) <- ~pickuplong + pickuplat
coordinates(Dropoff_d) <- ~Droplong + Droplat

# Set the projection using WGS84, logitude and latitude
proj4string(Dropoff_p) <- CRS("+init=epsg:4326")
proj4string(Dropoff_d) <- CRS("+init=epsg:4326")

# Visualize the data using mapview
map_p <- mapview(Dropoff_p, color = "red")
map_d <- mapview(Dropoff_d, color = "blue")

# See two maps together
map_p + map_d