【问题标题】:Visualization issue while using Leaflet使用 Leaflet 时的可视化问题
【发布时间】:2017-05-08 09:35:15
【问题描述】:

我有两个数据框如下:

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)) 

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)) 

我尝试在 pickup 数据帧 中找到在 dropoff dataframe 中重复的接送坐标(经度和纬度)。我有下面的代码,但我得到了这个错误:

library(sp)
library(rgdal)
library(leaflet)
library(mapview)
library(dplyr)
a <- semi_join(Dropoff , PickUP , by = c("pickuplong","pickuplat"))
a$ID <- 1:nrow(a) 
Dropoff_p <- a[, c("ID", "Pickup_longitude", "Pickup_latitude")]
Dropoff_d <- a[, c("ID", "Dropoff_longitude", "Dropoff_latitude")]
coordinates(Dropoff_p) <- ~Pickup_longitude + Pickup_latitude
coordinates(Dropoff_d) <- ~Dropoff_longitude + Dropoff_latitude
proj4string(Dropoff_p) <- CRS("+init=epsg:4326")
proj4string(Dropoff_d) <- CRS("+init=epsg:4326")
map_p <- mapview(Dropoff_p, color = "red")
map_d <- mapview(Dropoff_d, color = "blue")
map_p + map_d

我的错误是:

$tmp, "ID", value = c(1L, 0L)) 中的错误: 替换有 2 行,数据有 0 总结期间错误:无法打开 连接

【问题讨论】:

    标签: r leaflet r-leaflet r-mapview


    【解决方案1】:

    当对数据框进行子集化时,您必须使用相同的列名。我更改了Dropoff_pDropoff_dcoordinates(Dropoff_p)proj4string(Dropoff_d)中的列名,然后你的脚本就可以工作了。

    此外,mapview 软件包刚刚有了新的更新。如果需要,您可以将您的 mapview 更新为版本 2.0.1。您还可以添加col.regions = "red"col.regions = "blue",因为似乎在新版本下color 参数只会改变一个点的轮廓。要更改填充颜色,请使用col.regions

    library(sp)
    library(rgdal)
    library(leaflet)
    library(mapview)
    library(dplyr)
    
    a <- semi_join(Dropoff , PickUP , by = c("pickuplong","pickuplat"))
    a$ID <- 1:nrow(a) 
    Dropoff_p <- a[, c("ID", "pickuplong", "pickuplat")]
    Dropoff_d <- a[, c("ID", "Droplong", "Droplat")]
    coordinates(Dropoff_p) <- ~pickuplong + pickuplat
    coordinates(Dropoff_d) <- ~Droplong + Droplat
    proj4string(Dropoff_p) <- CRS("+init=epsg:4326")
    proj4string(Dropoff_d) <- CRS("+init=epsg:4326")
    map_p <- mapview(Dropoff_p, color = "red", col.regions = "red")
    map_d <- mapview(Dropoff_d, color = "blue", col.regions = "blue")
    map_p + map_d
    

    【讨论】:

    • 第二行出现错误,其中 a$ID
    • 您知道如何将地图上的圆形图标更改为其他形状,例如矩形。谢谢
    • @Behzad 我不知道是否有一种简单的方法可以将符号从圆形更改为矩形。请参阅mapviewenvironmentalinformatics-marburg.github.io/mapview/…leaflet 的文档了解更多信息。顺便说一句,如果我的解决方案至少可以解决您最初的问题。请接受它们作为答案。
    猜你喜欢
    • 2018-01-27
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 2022-10-08
    • 2020-08-22
    • 2020-12-04
    • 1970-01-01
    相关资源
    最近更新 更多