Skip to content
Bankn8II©$A edited this page Nov 5, 2024 · 2 revisions

Welcome to the DataVizR wiki!

OSM Administrative Boundary Level 6 (O06) leaflet

https://aibolem.github.io/DataVizR/mapping.html

image

image

image

https://gis.stackexchange.com/questions/29067/openstreetmap-neighborhood-boundaries

대한민국

https://global.mapit.mysociety.org/areas/O06.html

image

https://www.mysociety.org/advice-and-support/

공주시 ID 1194334 Type: OSM Administrative Boundary Level 6 (O06) Exists in generations: 9–10 Country: 대한민국, Global Get this data as JSON

How to add labels on top of polygons in leaflet

image

https://stackoverflow.com/questions/48147282/how-to-add-labels-on-top-of-polygons-in-leaflet

`library(raster) library(rgeos) library(leaflet)

Get UK polygon data

UK <- getData("GADM", country = "GB", level = 2)

Find a center point for each region

centers <- data.frame(gCentroid(UK, byid = TRUE)) centers$region <- row.names(UK)

Create dummy data

set.seed(111) mydf <- data.frame(place = unique(UK$NAME_2), value = sample.int(n = 1000, size = n_distinct(UK$NAME_2), replace = TRUE))

Create five colors for fill

mypal <- colorQuantile(palette = "RdYlBu", domain = mydf$value, n = 5, reverse = TRUE)

leaflet() %>% addProviderTiles("OpenStreetMap.Mapnik") %>% setView(lat = 55, lng = -3, zoom = 6) %>% addPolygons(data = UK, stroke = FALSE, smoothFactor = 0.2, fillOpacity = 0.3, fillColor = ~mypal(mydf$value), popup = paste("Region: ", UK$NAME_2, "
", "Value: ", mydf$value, "
")) %>% addLabelOnlyMarkers(data = centers, lng = ~x, lat = ~y, label = ~region, labelOptions = labelOptions(noHide = TRUE, direction = 'top', textOnly = TRUE)) %>% addLegend(position = "bottomright", pal = mypal, values = mydf$value, title = "UK value", opacity = 0.3)`

C World Map