Search code examples
rr-sfr-leaflet

Getting a base map instead of the one specified through data


I downloaded the shapefile to plot Iowa Counties from here - https://geodata.iowa.gov/dataset/county-boundaries-iowa/resource/183e782f-2d43-4073-8524-fe8e634cf17a

However, when I try plotting a map, I only get the base map and not County-level data.

mymap<-st_read("county.shp")
str(mymap)
library(leaflet)
# map the polygons in shp
mymap %>% 
  leaflet() %>% 
  addTiles() %>% 
  addPolygons()

In addition, I get the following warnings -

Warning messages:
1: sf layer is not long-lat data 
2: sf layer has inconsistent datum (+proj=utm +zone=15 +datum=NAD83 +units=m +no_defs).
Need '+proj=longlat +datum=WGS84' 

I am a beginner in this arena and would highly appreciate any assistance on this issue.


Solution

  • Using @jazzurro's comment as the answer for future seekers -

    mymap<-st_read("county.shp")%>% st_transform(crs = 4326)
    str(mymap)
    library(leaflet)
    # map the polygons in shp
    mymap %>% 
      leaflet() %>% 
      addTiles() %>% 
      addPolygons()
    

    Apparently, I had forgotten to specify the Coordinate Reference System which led to the issue.