-1

Name Lat Long XX -20.6544 150.9149

This is how my data looks like with over 1000 entries

The code I tried is below.

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

received these errors

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

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

Can someone help me. Thank you in advance.

1 Answers1

0

Looks like your data did not load correctly R cannot find the dataset Postcode. You need to try to download it or load the data another way. The long error is coming because the dataset never loaded so R can't find the long column

natalie
  • 204
  • 1
  • 4