尝试创建澳大利亚的气泡地图

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

名称经纬度 XX -20.6544 150.9149

这就是我的数据,有超过 1000 个条目

我尝试过的代码如下。

# Library

library(leaflet)

# load example data (Fiji EarthPostcode) + keep only 100 first lines
data(Postcode)
Postcode <-  head(Postcode, 100)

# Create a color palette with handmade bins.
mybins <- seq(4, 6.5, by=0.5)
mypalette <- colorBin( palette="YlOrBr", domain=Postcode$Name, na.color="transparent", bins=mybins)

# Prepare the text for the tooltip:
mytext <- paste(
   "Lat: ", Postcode$Lat, "<br/>", 
   "Long: ", Postcode$Long, "<br/>", 
   "Name: ", Postcode$Name, sep="") %>%
  lapply(htmltools::HTML)

# Final Map
m <- leaflet(Postcode) %>% 
  addTiles()  %>% 
  setView( lat=-27, lng=170 , zoom=4) %>%
  addProviderTiles("Esri.WorldImagery") %>%
  addCircleMarkers(~long, ~lat, 
    fillColor = ~mypalette(Name), fillOpacity = 0.7, color="white", radius=8, stroke=FALSE,
    label = mytext,
    labelOptions = labelOptions( style = list("font-weight" = "normal", padding = "3px 8px"), textsize = "13px", direction = "auto")
  ) %>%
  addLegend( pal=mypalette, values=~Name, opacity=0.9, title = "Name", position = "bottomright" )


# save the widget in a html file if needed.
# library(htmlwidgets)
# saveWidget(m, file=paste0( getwd(), "/HtmlWidget/bubblemapPostcode.html"))

收到这些错误

Warning message:
In data(Postcode) : data set ‘Postcode’ not found

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

有人可以帮助我吗。

r maps latitude-longitude r-leaflet bubble-chart
1个回答
0
投票

看起来您的数据未正确加载,R 找不到数据集邮政编码。您需要尝试下载它或以其他方式加载数据。出现长错误是因为数据集从未加载,所以 R 找不到长列

© www.soinside.com 2019 - 2024. All rights reserved.