I am trying to make a choropleth map with imported shapefiles of districts.
I think my data is aligned with map because one district I was expecting lit up(but I am not sure). The problem is that I cannot see the shp file boundaries.
I used the code below:
districtsg <-readOGR("sample/copyfile/Districts/Map_of_Districts_.shp")
districtsg <- sp::spTransform(districtsg, CRS("+proj=longlat +datum=WGS84"))
districtsg <-subset(districtsg,is.element(districtsg$NAME,fb$districtlive))
fb <- fb [order(match(fb$districtlive,districtsg$NAME)),]
bins <- c(0,10,20,30,40,50)
pal<-colorBin("YlOrRd",domain=fb$per.content, bins=bins)
m<- leaflet() %>%
setView(lng = -1.0232,lat=7.9465,zoom = 6) %>%
addProviderTiles(providers$Stamen.Toner)%>%
addPolygons(data =districtsg,
weight = 1,
smoothFactor = 0.5,
color = "Blue",
fillOpacity = 0.8,
fillColor= ~pal(fb$per.content),
highlight=highlightOptions(
weight = 5,
color = "#666666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE
))
m
labels <- paste( "<p>", fb$districtlive,"</p>",
"<p>", "% content:",round(fb$per.content,digits = 3),"</p>",
"<p>", "Total people that content:",round(fb$totalcontent,digits = 3),"</p>",
"<p>", "Total respondents from this district:",round(fb$totalrespondents,digits = 3),"</p>",sep = "" )
m<- leaflet() %>%
setView(lng = -1.0232,lat=7.9465,zoom = 6) %>%
addProviderTiles(providers$Stamen.Toner)%>%
addPolygons(data =districtsg,
weight = 1,
smoothFactor = 0.5,
color = "Blue",
fillOpacity = 0.8,
fillColor= ~pal(fb$per.content),
highlight=highlightOptions(
weight = 5,
color = "#666666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE
),
label = lapply(labels,HTML)) %>%
addLegend("topright",pal=pal, values = fb$per.content,
opacity = 0.7,
)
m
I looked around and found that the code below worked for someone, i tried it but it didn't work for me.
PRO <- sp::CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0')
DAT <- sp::spTransform(districtsg,PRO)
I am trying to make a choropleth map where districts boundaries can be seen and interacted with.
I used a sample data to do this and only one district was above 0. That district was the only that was coloured. I was expecting the other districts boundaries lines to present(and interactive) even if it had a 0% content and it was not coloured.
I did not get any error while doing this, it is just that, my map did look like what i was expecting.
I'd appreciate input on how to have my shape files on top of the tiles, with my data values present on top.