【问题标题】:Trying to create a bubble map of Australia尝试创建澳大利亚的气泡​​图
【发布时间】:2021-06-10 02:56:33
【问题描述】:

名字Lat Long 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

谁能帮帮我。提前谢谢你。

【问题讨论】:

  • Postcode 数据从何而来?
  • 这是我收集的数据。
  • 你保存在哪里,是什么格式的?
  • 以 CSV 格式保存在文件夹中。
  • 你使用了错误的函数,你不能使用data()来加载你的.csv文件。您需要使用文件阅读器,例如Postcode &lt;- read.csv("path/to/your/file.csv")

标签: r leaflet maps latitude-longitude bubble-chart


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-05
    • 2013-02-26
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多