R and Leaflet (a Javascript library) to plot schools on a very simple map and show the boundaries of local authority districts.
#install.packages("httpuv")
#install.packages("leaflet")
#install.packages("dplyr")
library(leaflet)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readr)
leaflet()%>%
addTiles()
r_MyHome <- leaflet() %>%
addTiles() %>% # use the default base map which is OpenStreetMap tiles
addMarkers(lng=90.409739, lat=23.757419,
popup="MyHome")
r_MyHome
https://data.humdata.org/dataset/bangladesh-healthsites#
bangladesh <- read_csv("bangladesh.csv")
## Parsed with column specification:
## cols(
## .default = col_character(),
## X = col_double(),
## Y = col_double(),
## osm_id = col_double(),
## completeness = col_double(),
## is_in_health_zone = col_logical(),
## water_source = col_logical(),
## changeset_id = col_double(),
## insurance = col_logical(),
## staff_doctors = col_logical(),
## contact_number = col_double(),
## electricity = col_logical(),
## operational_status = col_logical(),
## is_in_health_area = col_logical(),
## health_amenity_type = col_logical(),
## changeset_version = col_double(),
## addr_postcode = col_double(),
## staff_nurses = col_logical(),
## beds = col_double(),
## url = col_logical()
## )
## See spec(...) for full column specifications.
## Warning: 8 parsing failures.
## row col expected actual file
## 1218 addr_postcode a double ৫৮৪০ 'bangladesh.csv'
## 1553 contact_number no trailing characters , +8801611488026 'bangladesh.csv'
## 1609 contact_number no trailing characters -003686 'bangladesh.csv'
## 2334 health_amenity_type 1/0/T/F/TRUE/FALSE dialysis;x_ray 'bangladesh.csv'
## 2492 contact_number no trailing characters ,+8801676987262 'bangladesh.csv'
## .... ................... ...................... ................ ................
## See problems(...) for more details.
dhaka <- bangladesh %>%
filter(addr_city=="Dhaka")%>%
filter(!(X=="NA"))
m <- leaflet(dhaka) %>%
addTiles() %>%
addCircles(~X, ~Y, popup=dhaka$name)
m
## Different view
m <- leaflet(dhaka) %>%
addTiles() %>%
addCircles(~X, ~Y, popup=dhaka$name) %>% addProviderTiles(providers$CartoDB.DarkMatter)
m
m <- leaflet(dhaka) %>%
addTiles() %>%
addCircles(~X, ~Y, popup=dhaka$name) %>%
addProviderTiles("Stamen.Terrain")
m
m <- leaflet(dhaka) %>%
addTiles() %>%
addProviderTiles(providers$OpenTopoMap)%>%
addMarkers(lng=90.409739, lat=23.757419,
popup="MyHome")
m
http://leaflet-extras.github.io/leaflet-providers/preview/index.html
m <- leaflet(dhaka) %>%
addTiles() %>%
addCircles(~X, ~Y, popup=dhaka$name,weight = 13, radius=4, stroke = T, fillOpacity = 0.5,color="#ffa500")
m
summary(factor(dhaka$amenity))
## clinic dentist doctors hospital pharmacy NA's
## 81 74 32 84 650 17
pal <- colorFactor(c("green", "red","blue","black","navy"), domain = c("clinic", "hospital","dentist", "doctors","pharmacy" ))
leaflet(dhaka) %>%
addTiles() %>%
addCircleMarkers(
~X, ~Y,
color = ~pal(amenity),
stroke = TRUE, fillOpacity = 0.5,
popup=~amenity,
label=~as.character(amenity)
)
m <- leaflet(dhaka) %>%
addTiles() %>%
addProviderTiles("Stamen.Terrain")%>%
addCircles(~X, ~Y, popup=dhaka$name,weight = 13, radius=4, stroke = T, fillOpacity = 0.5)%>%
addAwesomeMarkers(lng=~X, lat=~Y,
popup=~amenity,
label=~as.character(amenity))
m
content <- paste(sep = "<br/>",
"<b><a href='https://www.linkedin.com/in/naimulislam19862020/'>Naimul Islam</a></b>",
"324,Mogbazar",
"Dhaka-1200"
)
m <- leaflet() %>%
addTiles() %>%
addProviderTiles("Stamen.Terrain")%>%
addPopups(lng=90.409739, lat=23.757419, content,
options = popupOptions(closeButton = FALSE)
)
m
content <- paste(sep = "<br/>",
"<b><a href='https://www.linkedin.com/in/naimulislam19862020/'>Naimul Islam</a></b>",
dhaka$X,
dhaka$Y
)
m <- leaflet(dhaka) %>%
addTiles() %>%
addProviderTiles("Stamen.Terrain")%>%
addPopups(lng=~X, lat=~Y, content,
options = popupOptions(closeButton = FALSE)
)
m
content <- paste(sep = "<br/>",
"<b><a href='https://en.wikipedia.org/wiki/List_of_hospitals_in_Bangladesh'>List of Health Facility</a></b>",
dhaka$name,
dhaka$amenity
)
m <- leaflet(dhaka) %>%
addTiles() %>%
addCircles(~X, ~Y, popup=content)
m
content <- paste(sep = "<br/>",dhaka$name,dhaka$amenity)
m <- leaflet(dhaka) %>%
addTiles() %>%
addMarkers(~X, ~Y, popup=content,
label = ~name,
labelOptions = labelOptions(noHide = F, direction = "bottom",
style = list(
"color" = "red",
"font-family" = "serif",
"font-style" = "italic",
"box-shadow" = "3px 3px rgba(0,0,0,0.25)",
"font-size" = "12px",
"border-color" = "rgba(0,0,0,0.5)") ))
m