Search code examples
rleafletr-leaflet

adding blank legend in R leaflet package?


Is there any way to add a 'blank' legend with just a title to a leaflet map using the R leaflet pacakge? I was hoping to mimic a map title using a blank legend.


Solution

  • You can use addControl() argument to add a legend and pass an html paragraph tags$p i.e. a string of text (here in bold, tags$b)

    library(leaflet)
    library(htmltools)
    
    my_title <- tags$p(tags$style("p {color: red; font-size:22px}"),
                tags$b("My_beautiful_title_goes here"))
    
    
    my_map <- leaflet() %>%
    addTiles() %>%
    setView(10.533, 45.822, zoom = 11) %>%
    addControl(my_title, position = "bottomright" )
    
    my_map