library(leaflet)
#--------------- Location of Edaicodu Veedu
n <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=77.16913, lat=8.47471,
popup="The birthplace of R")
n # Print the map
library(leaflet)
pal <- colorQuantile("YlOrRd", quakes$mag)
leaflet() %>%
# Basic markers
addTiles(group = "basic") %>%
addMarkers(data = quakes, group = "basic") %>%
# When zoomed in, we'll show circles at the base of each marker whose
# radius and color reflect the magnitude
addProviderTiles(providers$Stamen.TonerLite, group = "detail") %>%
addCircleMarkers(data = quakes, group = "detail", fillOpacity = 0.5,
radius = ~mag * 5, color = ~pal(mag), stroke = FALSE) %>%
# Set the detail group to only appear when zoomed in
groupOptions("detail", zoomLevels = 7:18)
## Assuming "long" and "lat" are longitude and latitude, respectively
## Assuming "long" and "lat" are longitude and latitude, respectively
leaflet() %>%
addTiles(group = "OpenStreetMap") %>%
addProviderTiles("Stamen.Toner", group = "Toner by Stamen") %>%
addMarkers(runif(20, -75, -74), runif(20, 41, 42), group = "Markers") %>%
addLayersControl(
baseGroups = c("OpenStreetMap", "Toner by Stamen"),
overlayGroups = c("Markers")
)
# !formatR
library(leaflet)
# a manual legend
leaflet() %>% addTiles() %>% addLegend(
position = "bottomright",
colors = rgb(t(col2rgb(palette())) / 255),
labels = palette(), opacity = 1,
title = "An Obvious Legend"
)
library(leaflet)
rand_lng <- function(n = 10) rnorm(n, -93.65, .01)
rand_lat <- function(n = 10) rnorm(n, 42.0285, .01)
random_data <- data.frame(
lng = rand_lng(50),
lat = rand_lat(50),
radius = runif(50, 50, 150),
circleId = paste0("circle #", 1:50),
lineId = paste0("circle #", 1:50)
)
# display circles (zIndex: 420) above the lines (zIndex: 410), even when added first
leaflet() %>%
addTiles() %>%
# move the center to Snedecor Hall
setView(-93.65, 42.0285, zoom = 14) %>%
addMapPane("ames_lines", zIndex = 410) %>% # shown below ames_circles
addMapPane("ames_circles", zIndex = 420) %>% # shown above ames_lines
# points above polygons
addCircles(
data = random_data, ~lng, ~lat, radius = ~radius, popup = ~circleId,
options = pathOptions(pane = "ames_circles")
) %>%
# lines in 'ames_lines' pane
addPolylines(
data = random_data, ~lng, ~lat, color = "#F00", weight = 20,
options = pathOptions(pane = "ames_lines")
)
# same example but circles (zIndex: 420) are below the lines (zIndex: 430)
leaflet() %>%
addTiles() %>%
# move the center to Snedecor Hall
setView(-93.65, 42.0285, zoom = 14) %>%
addMapPane("ames_lines", zIndex = 430) %>% # shown below ames_circles
addMapPane("ames_circles", zIndex = 420) %>% # shown above ames_lines
# points above polygons
addCircles(
data = random_data, ~lng, ~lat, radius = ~radius, popup = ~circleId,
options = pathOptions(pane = "ames_circles")
) %>%
# lines in 'ames_lines' pane
addPolylines(
data = random_data, ~lng, ~lat, color = "#F00", weight = 20,
options = pathOptions(pane = "ames_lines")
)
leaf <- leaflet() %>%
addTiles() %>%
# central park
fitBounds( -73.9, 40.75, -73.95, 40.8 ) %>%
addMeasure()
leaf
# customizing
leaf %>% addMeasure(
position = "bottomleft",
primaryLengthUnit = "meters",
primaryAreaUnit = "sqmeters",
activeColor = "#3D535D",
completedColor = "#7D4479",
localization = "de"
)
Add provider tiles
leaflet() %>%
addProviderTiles("Stamen.Watercolor") %>%
addProviderTiles("Stamen.TonerHybrid")
library(raster)
## Loading required package: sp
r <- raster(xmn = -2.8, xmx = -2.79, ymn = 54.04, ymx = 54.05, nrows = 30, ncols = 30)
values(r) <- matrix(1:900, nrow(r), ncol(r), byrow = TRUE)
crs(r) <- CRS("+init=epsg:4326")
if (requireNamespace("rgdal")) {
leaflet() %>% addTiles() %>%
addRasterImage(r, colors = "Spectral", opacity = 0.8)
}
library(leaflet)
#--------------- Location of Edaicodu Veedu
n <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=77.16913, lat=8.47471,
popup="The birthplace of R")
n # Print the map