library(leaflet)
data(quakes)
# symbol with a label centered inside
makeSymbol('circle', width = 24, color = 'black', fillColor = 'steelblue',
fillOpacity = 0.8, label = 'A')
# map markers with per-point labels
quakes$label <- as.character(seq_len(nrow(quakes)))
leaflet(quakes[1:20, ]) %>%
addTiles() %>%
addSymbols(lat = ~lat, lng = ~long, color = 'black',
fillColor = 'steelblue', fillOpacity = 0.8,
label = ~label)
library(leaflet)
data(quakes)
quakes1 <- quakes[1:10,]
# makeSymbolText returns a single SVG data URI
makeSymbolText(text = 'A', width = 30, color = 'red')
# makeSymbolTextIcons builds a vector of icons
iconSet <- makeSymbolTextIcons(text = LETTERS[1:nrow(quakes1)],
width = 30, color = 'white',
fillColor = 'navy')
leaflet(quakes1) %>%
addTiles() %>%
addMarkers(lng = ~long, lat = ~lat, icon = iconSet)
# addText draws text labels at each location
leaflet(quakes1) %>%
addTiles() %>%
addText(lng = ~long, lat = ~lat,
text = ~as.character(seq_len(nrow(quakes1))),
color = 'white', fillColor = 'red', width = 30)
# addTextSize scales text by a numeric variable
leaflet(quakes1) %>%
addTiles() %>%
addTextSize(lng = ~long, lat = ~lat,
text = ~as.character(round(mag, 1)),
values = ~mag, color = 'black', fillColor = 'yellow',
baseSize = 30)
Run the code above in your browser using DataLab