试图创建澳大利亚的气泡​​图

问题描述

名字拉长 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,"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 找不到数据集邮政编码。您需要尝试下载它或以其他方式加载数据。长错误即将到来,因为数据集从未加载所以 R 找不到长列