Leaflet“无法推断lng列”,但df显示已加载的经纬度和lng列数

问题描述 投票:0回答:1

我正在尝试将基本数据库绘制到Leaflet上。数据为带有“艺术家”“地址”“ lat”“ Lon”的csv]

structure(list(Artist = structure(1:6, .Label = c("50 Cent", 
"A Tribe Called Quest", "Aesop Rock", "B.I.G.", "Beastie Boys", 
"Big Daddy Kane"), class = "factor"), Address = structure(c(1L, 
4L, 2L, 3L, 1L, 1L), .Label = c("", "45 JOHN STREET SUITE 711 NEW YORK, NEW YORK, 10038 ", 
"Crown Heights", "Linden Boulevard and S192nd"), class = "factor"), 
    Lng = c(-73.79191, 73.759296, -74.007918, -73.963667, -73.910054, 
    -73.941774), lat = c(40.680859, 40.692427, 40.709348, 40.682806, 
    42.02039, 40.687218), Base.of.Operations = structure(c(4L, 
    2L, 3L, 1L, 1L, 1L), .Label = c("Brooklyn", "Jamaica", "Lower East-Side", 
    "South Jamaica"), class = "factor"), Significance = structure(c(3L, 
    5L, 2L, 4L, 1L, 1L), .Label = c("", "First place he recorded, El-Ps studio Definitive Records.", 
    "Grew Up", "Home", "Where \"Check the Rhyme\" was Shot"), class = "factor"), 
    Date.of.first.release = structure(c(3L, 4L, 1L, 6L, 2L, 5L
    ), .Label = c("11/1/1999", "11/15/1986", "2/6/2003", "4/17/1990", 
    "6/28/1988", "9/13/1994"), class = "factor"), X = c(NA, NA, 
    NA, NA, NA, NA)), class = "data.frame", row.names = c(NA, 
-6L))

我尝试将其用作CSV,tibble,data.frame,并选择各个列,但它会响应“ Lon” col不是对象。

library(dplyr)
library(leaflet)
library(sp)

"example" <- read_csv("database.csv", T)

df <- tibble("example")

map <- leaflet(df) %>%
  addTiles() %>%
  setView(lat=40.742054, lng=-73.769417, zoom = 9) %>%
  addMarkers(df)

map

我尝试调用addMarkers()中的列,但仍然出现错误。

database <- read.csv("map.csv")

db <- tibble(database)
    map <- leaflet(db) %>%
    addTiles() %>%
    setView(lat=40.742054, lng=-73.769417, zoom = 9) %>%
    addMarkers(lng = ~Lng, lat = ~lat)

Result
Error in eval(f[[2]], metaData(data), environment(f)) : 
object 'Lng' not found

什么是什么

r leaflet latitude-longitude
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.