Create a web page using R Markdown that features a map created with Leaflet.
Host your webpage on either GitHub Pages, RPubs, or NeoCities.
Here is the coding using leaflet and the output map showing the 5 biggest cities in Norway with their inhabitants:
library(leaflet)
# download.file("https://www.ssb.no/eksport/tabell.csv?key=222368","~/Downloads/cities.csv")
cities <- read.csv("~/Downloads/cities.csv",sep = ";")
cities <- cities[10:14,1:2]
cities[,3] <- c(10.7522,5.324383,5.7331,10.3951,10.2045)
cities[,4] <- c(59.9139,60.397076,58.9700,63.4305,59.7441)
names(cities) <- c("City","Population","Longitude","Latitude")
rownames(cities) <- NULL
cities$City <- as.character(cities$City)
cities$Population <- as.numeric(as.character(cities$Population))
mymap <- leaflet() %>%
addTiles() %>%
setView(lng=10.3951, lat=63.4305 , zoom=5) %>%
# addMarkers(cities$Longitude,cities$Latitude, popup = as.character(cities$Population), label = as.character(cities$City))
addCircleMarkers(data = cities, lat = ~Latitude, lng = ~Longitude,
radius = ~Population/50000, label = ~as.character(Population),labelOptions = labelOptions(noHide = TRUE, direction = "bottom", textOnly = TRUE),
stroke = FALSE, fillOpacity = 0.8)
mymap