library(leaflet)
data(quakes)
quakes1 <- quakes[1:10,]
colors <- c('blue', 'red', 'yellow', 'green', 'orange', 'purple')
i <- as.integer(cut(quakes$mag, breaks = quantile(quakes$mag, seq(0,1,1/6)),
include.lowest = TRUE))
leafImg <- system.file(sprintf('img/leaf-%s.png', colors),
package = 'leaflegend')
leafIcons <- icons(
iconUrl = leafImg[i],
iconWidth = 133/236 * 50, iconHeight = 50
)
leaflet(data = quakes) %>% addTiles() %>%
addMarkers(~long, ~lat, icon = leafIcons) %>%
addLegendImage(images = leafImg,
labels = colors,
width = 133/236 * 50,
height = 50,
orientation = 'vertical',
title = htmltools::tags$div('Leaf',
style = 'font-size: 24px;
text-align: center;'),
position = 'topright')
# use raster images with size encodings
height <- sizeNumeric(quakes$depth, baseSize = 40)
width <- height * 38 / 95
symbols <- icons(
iconUrl = leafImg[4],
iconWidth = width,
iconHeight = height)
probs <- c(.2, .4, .6, .8)
leaflet(quakes) %>%
addTiles() %>%
addMarkers(icon = symbols,
lat = ~lat, lng = ~long) %>%
addLegendImage(
images = rep(leafImg[4], 4),
labels = round(quantile(height, probs = probs), 0),
width = quantile(height, probs = probs) * 38 / 95,
height = quantile(height, probs = probs),
title = htmltools::tags$div(
'Leaf',
style = 'font-size: 24px; text-align: center; margin-bottom: 5px;'),
position = 'topright', orientation = 'vertical')
Run the code above in your browser using DataLab