Just the basics
library(leaflet)
m <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=3.7174, lat=51.0543, popup="I'm somewhere around here") %>%
setView(lng=3.7174, lat=51.0543, zoom = 12)
m # Print the map
I spent the whole time working on this code and encountered this problem
Anyhow, if you know how to fix this, please send me a mail @ geowizard at gmail.com Here is the code :
# Download data from https://data.stad.gent/datasets/wijken
Vlaanderen <- readOGR("StatSect/Shapefile/statsec.shp", "statsec")
Gent <- Vlaanderen[Vlaanderen@data$NISCODE == 44021,]
# to see type plot(Gent)
Gentpro <- spTransform(Gent, CRS("+proj=longlat +ellps=intl"))
BuiltArea <- read.csv("bebouwdeoppervlakte2.csv", encoding="latin1", sep=";", dec=".")
ChronicDis <- read.csv("chronischeaandoeningen2.csv", encoding="latin1", sep=";", dec=".")
palette <- colorBin(c('#f7fbff', '#deebf7', '#c6dbef', '#9ecae1', '#6baed6', '#4292c6', '#2171b5', '#08519c', '#08306b'),
bins = c(0, 5, 10, 15, 20, 25, 30, 40, 50, 60))
popup1 <- paste0("Built Area %","<br>District: ",
Gentpro$SECNAAM, #column containing the district names
"<br>Percentage: ",
BuiltArea$bebouwingsgraad_pct #column that contains the relative amount data
,"<br>Total km²: ",
BuiltArea$oppervlakte_km2 #column that contains the absolute amount data
)
popup2 <- paste0("Chronic Disease %",
"<br>District: ",
Gentpro$SECNAAM, #column containing the district names
"<br>Percentage: ",
ChronicDis$Percentage_personen_met_chronische_aandoeningen #column that contains the relative amount data
,"<br>Total : ",
ChronicDis$Aantal_personen_met_chronische_aandoeningen #column that contains the absolute amount data
)
mymap <- leaflet() %>%
addProviderTiles("Hydda.Full", options = tileOptions(minZoom=9, maxZoom=14)) %>% #"freeze" the mapwindow to max and min zoomlevel
addPolygons(data = Gentpro,
fillColor = ~palette(BuiltArea$bebouwingsgraad_pct),
fillOpacity = 0.6, ## how transparent do you want the polygon to be?
color = "white", ## color of borders between districts
weight = 1.5, ## width of borders
popup = popup1, ## which popup?
group="Built Area %")%>%
## for the second layer we mix things up a little bit, so you'll see the difference in the map!
addPolygons(data = Gentpro,
fillColor = ~palette(ChronicDis$Percentage_personen_met_chronische_aandoeningen),
fillOpacity = 0.2,
color = "white",
weight = 1.5,
popup = popup2,
group="Chronic Disease %")%>%
addLayersControl(
baseGroups = c("Built Area %", ## group 1
"Chronic Disease %" ## group 2
),
options = layersControlOptions(collapsed = FALSE))%>% ## we want our control to be seen right away
addLegend(position = 'topleft', ## choose bottomleft, bottomright, topleft or topright
colors = c('#f7fbff', '#deebf7', '#c6dbef', '#9ecae1', '#6baed6', '#4292c6', '#2171b5', '#08519c', '#08306b'),
labels = c('0','5','10','15','20','25','30','40','60'), ## legend labels (only min and max)
opacity = 0.6, ##transparency again
title = "%") ## title of the legend
mymap